concept

sticky-containing-block-limit — CSS reference

Sticky positioning cannot keep a box pinned beyond the containing block constraint. A short section inside a long scroll container can carry its sticky heading out of view as the section ends.

Formal Syntax & Structure

css syntaxcss
position: sticky; top: 0;

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS positioning lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#p{width:240px;height:160px;background:#e6eef2} #a{width:60px;height:30px;background:#128579} #b{height:20px;background:#adcde8}#p{overflow:auto;height:100px}#q{height:80px}#a{position:sticky;top:0}</style><body><div id="p"><section id="q"><div id="a">A</div></section><div style="height:300px"></div></div></body></html>
CSS Reference