Day 2 - CSS Positioning
The position property specifies the type of positioning
method used for an element.
1. Static Position (Default)
Elements display in order, as they appear in the document flow.
top, left, etc. have no effect.
Code:
Output:
2. Relative Position
Positioned relative to its normal position. Moving it does NOT affect the layout of other elements (it leaves a "ghost" space).
Code:
Output:
3. Absolute Position
Positioned relative to the nearest
positioned ancestor (like a parent with
position: relative). It is removed from the normal
document flow (no space reserved).
Code:
Output:
4. Fixed Position
Positioned relative to the viewport (browser
window). It stays in the same place even when scrolled.
Check the bottom-right corner of your screen!
Code:
5. Sticky Position
Toggles between relative and fixed based
on scroll position. It sticks when it reaches specific offset.
Code:
Output:
Scroll down inside this box...
Keep scrolling...
The purple header sticks!
6. Z-Index (Stacking Order)
Controls which element sits on top of another. Higher number = on top.