CSS Positioning
The position property is the key to advanced CSS layouts. It allows you to take elements out of the normal document flow and place them precisely where you want them, overlay content, or pin items to the screen.
Positioning Types
- Static: The default. Elements appear in the order they are in the HTML.
- Relative: Positioned relative to its normal position. Does not affect surrounding elements' layout.
- Absolute: Removed from the flow. Positioned relative to the nearest positioned ancestor (non-static).
- Fixed: Removed from the flow. Positioned relative to the browser window (viewport).
- Sticky: A hybrid. Acts relative until a scroll threshold is met, then becomes fixed.
The Coordinate Properties
Once an element is positioned (anything other than static), you can use top, right, bottom, and left to move it. These properties also accept negative values.
Z-Index and Stacking
When elements overlap, z-index determines the stack order. An element with a higher z-index covers one with a lower z-index. Note that z-index only works on positioned elements.
