Sticky Positioning: Scroll Thresholds and Section Bounds
2026-11-19

Sticky Positioning: Scroll Thresholds and Section Bounds

Sticky positioning keeps an element in normal layout flow while allowing its visible position to shift against a scrollport threshold. Its movement is also limited by the containing block. Understanding those two boundaries explains why a heading can remain near the top for a while and later move away as its own section ends.

The inset refers to the relevant scrollport

The CSS Positioned Layout specification defines sticky positioning relative to the nearest relevant scrollport. A non-auto inset such as top twenty pixels establishes an edge of the sticky view rectangle. The element's visible box is shifted inward when needed, within its containing-block constraint.

The threshold is not simply an instruction to move the original document position down by twenty pixels. While the normal position remains comfortably below that threshold, no sticky correction is needed. Only after scrolling would move it past the threshold does the correction become active.

The following calculation is a deliberately simplified one-axis illustration. It uses no margins, transforms or complicated layout relationships. It is an independently computed geometric model, not a claim that an actual browser screenshot or a production page was tested.

Scroll0,120,150givesvisible150,30,20withnormal150,30,0.
The computed illustration preserves flow position and a top inset of twenty; it is not a browser screenshot. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

A normal position moves until it reaches the threshold

Let the scrollport height be two hundred pixels. The element's normal document top is one hundred fifty, its box height is forty and its top inset is twenty. Its containing block extends from document position one hundred to five hundred. Additional document content extends farther, permitting the later scroll positions used here.

At scroll offset zero, the normal top appears at one hundred fifty in scrollport coordinates. It is below the top threshold, so it remains there. At scroll offset one hundred twenty, the normal top appears at thirty and still needs no correction.

At scroll offset one hundred fifty, the normal top would be zero. Sticky positioning shifts the visible top to twenty, while the containing block still has ample room below. The normal-flow location remains part of the layout even though the visible position has been adjusted.

The containing block eventually limits that correction

At scroll offset four hundred fifty, the containing block's bottom appears at fifty in scrollport coordinates. A forty-pixel box placed at top twenty would end at sixty, beyond that bottom. The box therefore cannot retain that placement while remaining within its containing block.

The simplified model places its top at ten, making its bottom fifty. It has moved above the twenty-pixel threshold because the containing block's end limits the allowed sticky correction. Relative to its uncorrected normal top of minus three hundred, the correction is still downward; the example does not contradict the rule that a top-only sticky inset pushes downward from normal position.

For these assumptions, the visible top is the smaller of the top-threshold-clamped normal position and the containing bottom minus the box height. This compact formula is a model for the stated simple geometry, not a complete replacement for the specification's margin, writing-mode and multiple-inset rules.

Containingbottom50andheight40forcevisibletop10ratherthantop20.
The parent section end limits the allowed displacement while normal-flow space remains in layout. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

The scroll ancestor can differ from the visible page scroll

The MDN position reference explains that a sticky box responds to its relevant scrolling ancestor. An ancestor with a scrolling mechanism can become the reference even when a different outer surface is the one a reader notices moving.

A page investigation should therefore identify the actual scroll container before comparing the threshold with the browser window. Applying the rule to the wrong coordinate system can make a correct sticky relationship look like a failure. The element's containing block is another boundary and need not be the same object as the scrollport.

If both insets for an axis are auto, sticky positioning does not add an offset on that axis. Specifying a vertical threshold does not automatically create a horizontal threshold too. The example intentionally uses only top, leaving the other complexities outside its numeric model.

The visible shift does not remove normal-flow space

Sticky positioning preserves the element's normal layout participation. Other content is not automatically pulled into its original place as though the box had been removed from flow. Multiple sticky elements can also be offset independently and can overlap; the property does not itself arrange a stacked set of headings.

The examples compute normal coordinates, threshold correction and containing-block cap separately. They do not adjust image file dimensions, upload assets or claim that any site's layout has been repaired. Preserve all three positions when explaining why a sticky element moves or stops. Related material appears in the web layout methods section and the technical article archive.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我