I'd like to have a header with one sticky element and one non-sticky element. Hence, the structure would be something like this:
body {
margin: 0;
height: 2000px;
}
header {
position: static;
border: 1px solid blue;
overflow: visible;
}
.sticky-yes {
position: sticky;
top: 0;
border: 1px solid blue;
}
.sticky-no {
position: relative;
top: 0;
border: 1px solid orange;
}
<header>
<div class="sticky-yes">Sticky</div>
<div class="sticky-no">Not sticky</div>
</header>
<div>... Rest of the webpage ...</div>
The header sits as a direct child of the body.
As far as I know, sticky elements want to stick to the nearest ancestor with a "scrolling mechanism". And I can "ignore" the parent element by giving it position: static;
I also added overflow: visible;
to the parent after reading this related question: CSS - Allow an div to stick out of its parent
But this snippet won't work.
I am constrained to use it with that markup, I cannot move the sticky element outside of the header.
What approach can I take?