【发布时间】:2020-11-09 05:45:54
【问题描述】:
我需要一个相对于父 div 的粘性标题。目前,Header 仅在部分 div 上具有粘性。 但我想要一个相对于父类的粘性标题。
HTML 代码
<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>
这是我的 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;
}
我想要一个如下所示的粘性标题
Header 1
Header 2
Header 3
【问题讨论】:
-
请帮我分享你的知识。我尝试过但没有解决任何问题。