DEV Community

Higor Neves Marques
Higor Neves Marques

Posted on

How really works the CSS position property

I have seen a lot of developers using the CSS position property in a wrong way or by try and test "technic", some times, not only the beginners but some mid-level developer also.

So, I decided to write this article to explain how the position rule works.

position: static;

Is the default value for any HTML element. It makes the element follow the standard HTML flow, putting each element after the previous element and before the next element on the DOM.

Alt Position Static Gif

position: relative;

The relative value works like the static one, but now you can set top, right, bottom and left values for this element.

Also, relative elements are used as a reference for absolute children elements.

Alt Position Relative Gif

position: absolute;

Elements with absolute position are removed from the flow of the document. Other elements will follow the flow normally.

Important to know, top, right, bottom and left of absolute elements will refer to the first relative parent.

Alt Position Absolute Gif

position: fixed;

Is very similar to position: absolute;, but the fixed elements will refer to the document instead a parent.

Alt Position Fixed Gif

position: sticky; (experimental)

the element is treated as a relative value until the scroll location of the viewport reaches a specified threshold, at which point the element takes a fixed position where it is told to stick.

Conclusion

I hope this article can help you to understand and use position CSS property with more efficiency.

Thanks for reading ;)

Top comments (8)

Collapse
 
georgewl profile image
George WL

Could do with another proofreading and editing tbh.

Otherwise, a pretty good article

Collapse
 
higormarques profile image
Higor Neves Marques

Hi, thanks:)

Do you have any suggestions to improve it?

Collapse
 
georgewl profile image
George WL

The content is really well thought out, I can tell that.

Just the wording feels a little clumsy, I'd have a friend who's great at grammar give it a read through.

Thread Thread
 
higormarques profile image
Higor Neves Marques

I understand, English is not my mother language, so Some times is hard to me use better words, I have to improve my vocabulary, this is my second article in English. Thanks for the feedback, it will help me a lot ๐Ÿ˜ƒ.

Thread Thread
 
steelwolf180 profile image
Max Ong Zong Bao

You could consider using Grammarly i use it for helping me in writing & editing my article.

Thread Thread
 
higormarques profile image
Higor Neves Marques

Sure, I will try it.

Thanks ๐Ÿ˜†

Collapse
 
mpuckett profile image
Michael Puckett

Oo pretty. How did you make the animations?

Collapse
 
higormarques profile image
Higor Neves Marques

Hi Michael, I did a search at google and found that, to be honest ๐Ÿ˜‚.