-
Notifications
You must be signed in to change notification settings - Fork 715
[css-position][css-sticky] Position: sticky doesn't work when it has several HTMLElements with margin before it #3923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Konrud Your example has less to do with margins and more to do with the fact that the ancestor within which your sticky element is attempting to stick[1] has a height set too short to be in view when scrolling down to view/reach the sticky element. In other words, remove the [1] Creation of Sticky-Constraint Rectangles - https://drafts.csswg.org/css-position-3/#sticky-pos
|
@jonjohnjohnson thank you for your response. |
No, the sticky position scheme is not simply a "fixed-like" position scheme for any scrollport. It is something that allows an element to effectively stay in flow, retaining its geometry unless the "intersection" of its containing block and its scroll container allow it to stick to an edge/offset at a certain length. Key here being that it needs room to move within its containing block. And your example doesn't allow any space for it to move within the This is a feature of sticky. Not a bug or omission. Please read all the language about boxes and sticky-constraint rectangles in that section, because sticky is not just about vertical scrolling, it doesn't mention See this demo to understand why it's important for a sticky element to be constrained within a containing block, here the nearest block level ancestor. Without which, every sticky element could never become "unstuck" at any point, each staying in view and covering each other. Think about how alphabetical label are treated in contacts/phonebook apps like on iOS? See how sticky labels can "push" each other out from being "stuck" when reaching the end of their containers box/height? |
@Konrud If you want the |
This is if you are ok with your scrollport not matching the size of the window, leaving extra unused space in the viewport or worse cutting off parts of this body scrollport when the viewport is shorter than 720px. You also lose browser viewport/root scroller "conveniences", such as operas and iOS Safaris ability to click on the browsers chrome to scroll to the top of the document or chromes overscrolling rubber banding. |
Ah, yeah, this is an odd intersection of some features. The stickypos's parent (and containing block) is That's why you're seeing it stick if there's nothing preceding it - if the stickypos element starts out within the 720px-tall If you remove the Since I don't understand why the |
Steps to reproduce the problem:
<p>
element with text and optionally withmargin
and some other elements before the element you want to set as a stickysticky; top: 0;
on the element, you want to be stickyWhat is the expected behavior?
The element should behave as a sticky element.
What went wrong?
The element stays in its place and doesn't behave as a sticky.
Code example: http://bit.ly/2HeL6Si
NOTE:
Position sticky won't work until there are HTMLElements before it in the DOM e.g.
<p>
element with margin. If you, however, delete all the elements before it in the DOM position sticky will work as expected.Chrome version: 74
OS Version: Windows 7
The text was updated successfully, but these errors were encountered: