CSS Positioning
Escape the normal document flow. Master static, relative, absolute, fixed, sticky, and the 3D stacking context of z-index.
Where Do Elements Anchor?
staticThe Default. Natural document flow. top, left, and z-index are completely ignored!
relativeThe Ghost Footprint. Shifts from where it would have been, but leaves its space reserved. Also acts as anchor for absolute children!
absoluteRipped from Flow. Takes zero space. Teleports relative to its closest non-static ancestor (usually a position: relative parent).
fixedGlued to Viewport. Anchored to the browser screen glass. Never moves, even when user scrolls (e.g. sticky headers, back-to-top buttons).
stickyThe Hybrid. Behaves like relative until scroll threshold (e.g. top: 0) is reached, then sticks like fixed!
Inspect Relative vs Absolute Movement
The Parent `relative` + Child `absolute` Pattern
How do you place a badge on the top-right corner of a card? Or a close icon on a modal dialog?
Full Positioning Visualizer
Positioning & Transforms Studio
Master the vital difference between CSS Positioning (normal flow offsets) and CSS Transforms (GPU-accelerated translate, scale, and rotate).
Try these
- Switch between static and relative: Notice offsets (top/left) only take effect when not static.
- Choose absolute and toggle "Parent has position: relative": Watch the box escape to the outer viewport when parent is static!
- Select sticky and scroll inside the preview stage to see it stick once reaching top: 24px.
- Adjust z-index to see the card dive underneath or rise above sibling elements.
Shifted (24px, 32px) from original slot.
9. Floats & Clearfix
Text wrapping around images, clearfix micro-hacks, and Block Formatting Contexts.