Absolute Positioning

Absolute Positioning

In CSS there are a couple of different positioning modes, but the more important ones we will talk about for now are the normal flow and absolute positioning.

Normal Flow

It is simply the default positioning of our elements on our page or we can also achieve the normal flow by setting the position to the relative value.

/** Default postioning **/
postion: relative        

In this case, we say that an element is in flow, which means the elements are laid out according to the source code in the HTML. This is very straightforward. Just keep in mind that is called normal flow.

Absolute Positioning

Setting an element's position property to absolute allows us to place it anywhere on the page. This removes the element from the normal flow, causing it to lose any impact on surrounding elements and potentially overlap them. To position an absolutely positioned element, use the top, bottom, left, or right properties, relative to a relatively positioned container

To understand this we need to practice and create the following container.

Output in the browser

We will create a Sale button on the top-left of the box.

Html Code


First, we need to understand that we have three classes: the parent class, product, and two other classes, product-title and sale

Next, we need to set the .product class to position: relative to the normal flow.

product class css

Then, we will set the .sale class to position: absolute and adjust the top and left properties to position the button. Alternatively, we can use any combination of top, left, bottom, and right to achieve the desired placement.


sales class css

Feel free to experiment with positioning live by updating the top, left, bottom, and right properties using this URL ??


To sum up, this article guides you through positioning elements with CSS by setting a parent class to relative and child elements to absolute, allowing precise control over their placement. Experiment live and unleash your creativity using the provided URL!

compare normal flow and absolute


Written by Qabas, Web Developer. This is one of many articles on CSS.



Hamzah Alnofli

Frontend dev | Computer Science student at SQU

5 个月

This is some great info! Thanks for putting in the efforts

回复
Isra Al Rasbi

Computer Science | Cybersecurity and Computing Infrastructure

5 个月

Well said!

要查看或添加评论,请登录

Qabas Al-Mamari的更多文章

  • JWT - Token Authentication

    JWT - Token Authentication

    Suppose we request our API and it should return data. Tokens are a good thing to use with an API because they are small…

  • Storing Passwords in the Database

    Storing Passwords in the Database

    This article looks at how we can store something like a password in a database. Now it goes without saying that the…

    1 条评论
  • JSON vs XML

    JSON vs XML

    Types of Web Services: JAX-WS: Communication using XML, provides for message-oriented and RPC services, uses SOAP…

  • What is BPMN?

    What is BPMN?

    The main benefit of BPMN is that allows you to create and share diagrams that business stakeholders will readily…

社区洞察