CSS – Position

The positions in the CSS as the name suggests set the positioning method for an element on a web page. To set positions, the positions property is used in CSS. The positions property is placed first and then the top, bottom, left, and right properties are used on a web page in CSS.

The following are the different values for positioning:

  • The static positioning in CSS
  • The relative positioning in CSS
  • The fixed positioning in CSS
  • The absolute positioning in CSS

Let us learn the values one by one with examples, beginning with static.

The static positioning in CSS

The default positioning for elements on a web page is static. That means an HTML element set static is positioned according to the normal flow of the web page. To set static positioning, use:

Let us now see an example to implement static positioning on a web page:

Output

CSS Position static positioning

The relative positioning in CSS

To position an element relative to its normal position, use the position: relative; property in CSS. The relative position property is placed first and then the top, bottom, left, and right properties are used on a web page for adjustment.

Let us see an example to implement relative positioning:

Output

CSS Position relative positioning

The fixed positioning in CSS

To position an element to be fixed on a web page, use the position: fixed; property in CSS. The fixed position property is placed first and then the top, bottom, left, and right properties are used on a web page for positioning the element.

Let us see an example to implement fix positioning in CSS:

Output

CSS Position fixed positioning

The absolute positioning in CSS

To position an element relative to the 1st parent element i.e. the nearest ancestor, use the position: absolute; property in CSS.

Let us see an example to implement absolute positioning in CSS:

Output

CSS Position absolute positioning

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


Read More:

CSS - Transitions
CSS - Buttons
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading