JSFiddle - React, Tailwind, and code Playground
HTML
Lorem Ipsum
<div class="this-parent-div-is-necessary">
<div class="div-sticky-class">
Test
</div>
<div>Lorem ...</div>
<div>Lorem ...</div>
<div>Lorem ...</div>
<div>Lorem ...</div>
<div>
<p>It will works here too</p>
</div>
</div>
Won't work here because it's outside the parent of div-sticky-class
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
CSS
.div-sticky-class{
color: red;
position: sticky;
position: -webkit-sticky;
top: 0;
}