Position: sticky doesn't seem to work for me when I apply it to a child of a div. How to solve?
HTML:
Lorem Ipsum
<div class="this-parent-div-is-necessary">
<div class="div-sticky-class">
Test
</div>
</div>
Lorem Ipsum
CSS:
.div-sticky-class{
color: red;
position: sticky;
position: -webkit-sticky;
top: 0;
}
Example: https://jsfiddle.net/n8Le2tva/
div
CSS?overflow:auto
in a parent element preventssticky
from functioning in Safari. I assume Safari is a concern based on your use of-webkit-sticky
– Juvenilitydisplay:contents
jsfiddle.net/n8Le2tva/1 but what's the point ?display:inline
would do too jsfiddle.net/n8Le2tva/2 – Chutneybr
s inside of the parent, your parent is too short for it to stick, it is sticky relative to the parent div – Nyx