![]() |
VOOZH | about |
CSS positioning is used to control the placement of elements on a web page. It allows elements to be positioned relative to the normal document flow, the browser window, or other elements.
Given below the different types of Positioning:
Static is the default position of an element. It does not accept properties like top, left, right, or bottom.
Relative positioning places an element relative to its normal position. You can move it using top, left, right, or bottom.
Box 2 is shifted 20px down and 30px to the right from its normal position.
Absolute positioning removes the element from the document flow and places it relative to the nearest ancestor with a positioning context (relative, absolute, or fixed).
Fixed positioning removes the element from the flow and positions it relative to the viewport. It remains in place even when the page scrolls.
The fixed element stays at the top-right corner of the viewport even as the user scrolls.
Sticky positioning switches between relative and fixed based on the scroll position.
The sticky element stays at the top of the viewport as you scroll but only within its containing element.