position changes normal flow behavior and enables controlled placement with offsets.
Position modes
static(default flow)relative(offset from own spot)absolute(positioned against nearest positioned ancestor)fixed(anchored to viewport)sticky(hybrid flow + fixed threshold)
Pitfall
Absolute positioning without a positioned parent often causes “mystery jumps” to unexpected anchors.
Important interview questions and answers
- Q: When does
absoluteuse the viewport?
A: When no ancestor establishes a positioning context. - Q: Why add
position: relativeto parent?
A: To scope absolute children reliably within that component. - Q: Common sticky failure?
A: Parent overflow/height contexts that prevent sticky thresholds from triggering.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.