Lesson 11 of 50
cssPositioning
11 mins
Course progress22%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 11 of 50
css11 mins
Keep these ideas in mind as you work through the lesson.
CSS positioning moves an element outside or inside the normal document flow.
| Value | Description |
|---|---|
static | Default – element follows normal flow. |
relative | Offset from its static position; space is still reserved. Good for slight nudges or for establishing a positioned ancestor for absolute children. |
absolute | Removed from flow; positioned relative to the nearest positioned ancestor (relative, absolute, fixed, sticky). |
fixed | Removed from flow; anchored to the viewport (doesn't move on scroll). |
sticky | Acts like relative until a scroll threshold is met, then behaves like fixed. Perfect for sticky headers or table‑of‑contents. |
header {
position:sticky;
top:0; /* sticks when its top reaches the viewport top */
background:#fff;
z-index:10; /* stay on top of other content */
box-shadow:0 2px 4px rgba(0,0,0,0.1);
}
+-------------------+ <-- .parent (position:relative)
| .child (absolute) |
+-------------------+
top/left/right/bottom are calculated relative to the parent, not the document.If you forget to give the ancestor a position value, an absolute child will jump to the document root, breaking your layout. Always double‑check the ancestor chain.