I need a sticky header relative to parent div. Currently, Header is sticky only on a section div. But I want a sticky header relative to a parent class.
HTML code
<div class="parent">
<div class="section-one">
<h1>Header 1</h1>
<div class="content">
content 123
</div>
</div>
<div class="section-two">
<h1>Header 2</h1>
<div class="content">
content 789
</div>
</div>
<div class="section-three">
<h1>Header 3</h1>
<div class="content">
content 456
</div>
</div>
</div>
Here is my css,
.parent {
position: relative;
}
.section-one h1{
position: sticky;
top: 0;
z-index: 9999;
}
.section-two h1{
position: sticky;
top: 50;
z-index: 9999;
}
.section-three h1{
position: sticky;
top: 100;
z-index: 9999;
}
I want a sticky header as per below
Header 1
Header 2
Header 3