HTML & CSS · Middle · Question 29 of 75
position: sticky isn't working even though top: 0 is set. What's the most likely cause?
- 1The element has no
z-index, so it stays under the content - ✓Correct answer: One of the ancestors has
overflow: hidden,autoorscroll - 3
stickydoesn't work inside semantic elements like<header>
Explanation
A sticky element sticks to its nearest scrolling ancestor. If an ancestor's overflow isn't visible, sticky is measured against it, and that ancestor may not scroll at all - visually nothing happens. Another cause: the parent is no taller than the element, so there's nowhere to stick. To clip without creating a scroll container, use overflow: clip.