css 当滚动容器中的其他分层/嵌套内容时,如何修复单个嵌套 div?
我看过许多关于固定位置元素主题的有趣帖子,但我有一个无法解决的问题。
我在滚动 div 容器内有许多嵌套的 div,如我的示例 此处
<div id="bottom" class="bottombox">
<div id="first" class="firstbox">
<div id="second" class="secondbox">
<div id="third" class="thirdbox">
<div id="top" class="topbox">
</div>
</div>
</div>
</div>
.bottombox
{
margin-top:0px;
margin-left:0px;
Position: absolute;
width: 200px;
height:200px;
overflow:auto;
background-color: darkblue;
}
.firstbox
{
margin-top:10px;
margin-left:10px;
width: 700px;
height:50px;
background-color: lightblue;
}
.secondbox
{
margin-top:20px;
margin-left:10px;
Position: absolute;
width: 700px;
height:50px;
background-color: brown;
}
.thirdbox
{
margin-top:30px;
margin-left:10px;
width: 100px;
height:100px;
/*Position: fixed;*/
background-color: white;
}
.topbox
{
margin-top:40px;
margin-left:10px;
width: 700px;
height:500px;
background-color: darkgray;
}
如您所见是许多一起滚动的“层”。我遇到的问题是,我只想让白色盒子相对于底部盒子保持固定,底部盒子实际上是容器。
这可以用 CSS 来完成吗?如果没有,那么Jquery动态更新它的位置呢?
I have seen a number of interesting posts on the subject of fixed position elements, but I have a problem that I can't solve.
I have a number of nested divs inside a scrolling div container as in my example here
<div id="bottom" class="bottombox">
<div id="first" class="firstbox">
<div id="second" class="secondbox">
<div id="third" class="thirdbox">
<div id="top" class="topbox">
</div>
</div>
</div>
</div>
.bottombox
{
margin-top:0px;
margin-left:0px;
Position: absolute;
width: 200px;
height:200px;
overflow:auto;
background-color: darkblue;
}
.firstbox
{
margin-top:10px;
margin-left:10px;
width: 700px;
height:50px;
background-color: lightblue;
}
.secondbox
{
margin-top:20px;
margin-left:10px;
Position: absolute;
width: 700px;
height:50px;
background-color: brown;
}
.thirdbox
{
margin-top:30px;
margin-left:10px;
width: 100px;
height:100px;
/*Position: fixed;*/
background-color: white;
}
.topbox
{
margin-top:40px;
margin-left:10px;
width: 700px;
height:500px;
background-color: darkgray;
}
As you can see there are a number of "layers" which scroll together. The problem I have is that I want just the white box to stay fixed in relation to the bottom box which is in effect the container.
Can this be done with CSS? If not, what about Jquery to dynamically update its position?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想不出任何方法可以在 CSS 中执行此操作,但这里有一个 jquery 解决方案:
http://jsfiddle。网/drHam/7/
I can't think of any way to do this in CSS, but here's a jquery solution:
http://jsfiddle.net/drHam/7/
我认为纯 CSS 是不可能实现的。
我用jquery制定了一个解决方案,请参阅更新的小提琴:
I think this is not possible with pure CSS.
I worked out a solution with jquery, see updated fiddle: