HTML & CSS · Junior · Question 21 of 75
How does position: sticky; top: 0 work?
- 1The element is always pinned to the top of the window like
fixed, regardless of its parent - ✓Correct answer: The element stays in flow until scrolling reaches
top: 0, then "sticks" - within its parent - 3The element sticks to the top of its parent and never scrolls, even when the parent leaves the screen
Explanation
sticky is a hybrid of relative and fixed: before the threshold it's in flow, after it - pinned until its parent container ends. Common reasons sticky "doesn't work": no top is set, an ancestor has overflow: hidden/auto, or the parent is no taller than the element itself.