CSS Positions

ยท

2 min read

JS Array and its Methods (5).png

Why do we use position property in CSS ?

Knowing CSS Positions helps you design beautiful interfaces with ease. CSS allows different methods for positioning elements. We'll explore all the various position types and learn about their implementation.

The position property allows us to define the position of an element.

We have 5 Positions :

1.Static

2.Relative

3.Absolute

4.Fixed

5.Sticky

1.Static-

Default value. Elements render in order, as they appear in the document flow.

image.png

2.Relative-

The element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position.

image.png

3.Absolute-

The element is positioned relative to its first positioned (not static) ancestor element.

image.png

4.Fixed-

The element is positioned relative to the browser window

image.png

5.Sticky-

The element is positioned based on the user's scroll position A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).

Reference- blogs.sayuri.tech/learn-css-positioning-und..

Sticky

Conclusion-

Thanks a lot for reading and hope now you know about CSS Positons. For more information please checkout MDN docs.And don't forget to hit a ๐Ÿ‘ if you find this article helpful. Happy learning! ๐ŸŽ‰

Resources-

1.MDN docs

2.W3Schools

3.TutorialPoint

ย