The market’s glass notice board with a paper Mr. Karim winds on: pick the position of Grandma Marni’s PROMO tag and scroll the paper, and the browser shows…
Elements floating in odd places, a badge that runs to the page corner, a sticky header that will not stick: nearly all of it is about the reference the browser uses. Knowing each value’s reference (the flow, a positioned ancestor, the viewport, the scroller) ends the guessing at top/left numbers.
absolute is measured from the nearest ancestor whose position is not static
position: absolute jumps to the page corner There is no positioned ancestor, so the reference is the start of the page. Give the intended parent position: relative.position: sticky will not stick Check three things: a top (or bottom) is set; no ancestor between the element and the scroller you mean has overflow: hidden/auto; and its parent is taller than it, since sticky only sticks while its parent is in view.z-index has no effect z-index only works on positioned elements (not static) or flex/grid items. Set position first (relative is enough). If it still loses, see the Stacking Context explorer.relative, set top: 20px The tag moves down, a dashed ghost marks its old spot, and line 5 does not move: the room stays reserved.absolute with .card still static Line 5 moves up into its spot, and its reference turns out to be .page: there is no positioned ancestor.position: relative The reference box moves to .card. offsetParent says the same.sticky, top: 0, then wind the paper The tag moves with the paper, then sticks to the top edge of the glass until its .card runs out.