I have a div in my website and have another div inside it, I gave the inner div position sticky and top:0 but it doesn't work! This is my code example:
Above : container is a normal div and inner div has a sticky position and top: 0 But it doesn't work. Any suggestions to solve this!
.sticky-div{
background: #fed700;
position: sticky;
top: 0;
}
<div class="container">
<nav>
<li>item1</li>
<li>item1</li>
</nav>
<div class="sticky-div">
Sticky
</div>
</div>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>