【发布时间】:2019-07-22 10:51:52
【问题描述】:
我在顶部有可滚动文本,它根据下面的内容具有动态高度,该文本具有粘性标题,其下方也具有动态高度,我正在尝试添加另一个粘性标题,但是对于第二个标题,我不确定我应该在多少顶部给?有什么技巧可以在运行时计算位置还是有其他方法?
.container {
height: 200px;
overflow: scroll;
}
.content {
background-color: gray;
}
.header1 {
position: sticky;
top: 0px;/* or whatever you wish to see it sticks */
background-color: red;
}
.header2 {
position: sticky;
top: 0px;/* how to stick thi div below header1 */
background-color: blue;
}
.footer {
/*top: 10px;*//* useless if position is not reset to fixed,absolute or sticky */
background-color: yellow;
height: 400px;
}
<div class="container">
<div class="content"> runtime example text<br> runtime example text<br> runtime example text </div>
<div class="header1"> header text runtime dynamic text </div>
<div class="header2"> header text </div>
<div class="footer"> footer text </div>
</div>
【问题讨论】:
-
@Junior 它不重复,给定示例具有固定高度,但我正在尝试具有动态高度的 div。请删除重复标记,以便其他人查看
-
我的 div 也没有相互嵌套