我想知道是否有人为此找到了解决方案?
我正在寻找一个解决方案,将元素附加到滚动容器的顶部
HTML:
<div class="container">
<div class="header">title</div>
<div class="element">......</div>
... (about 10-20 elements) ...
<div class="element">......</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所有"元素"都有position:relative,
容器有以下CSS:
.container {
position:relative;
width:200px;
height:400px;
overflow-y:scroll;
}
Run Code Online (Sandbox Code Playgroud)
我希望标题保持在容器的顶部,独立于其滚动位置和滚动在下面的元素.
到目前为止的CSS:
.header {
position:absolute; /* scrolling out of view :-( */
z-index:2;
background-color:#fff;
}
.element{
position: relative;
}
Run Code Online (Sandbox Code Playgroud)
所有元素都是块元素,我不能将标题移动到容器之外.jquery在这一点上是没有选择的.