【发布时间】:2013-04-20 21:37:35
【问题描述】:
我想在一个带有overflow-y:scroll的div内有一个固定位置的div,这意味着我希望div保持在原位,而其余内容正常滚动。 而且我不知道出了什么问题,有人可以帮忙吗?提前谢谢...
.foo {
position:relative;
display:block;
width:100%;
height:300px;
overflow-y:scroll;
}
.bar {
position:fixed;
top:0;
right:0;
}
这里是 HTML
<div class="foo">
<div class="bar"><div><!-- end of div that should be fixed -->
<div class="someOther">...</div>
<div class="someOther">...</div>
<div class="someOther">...</div>
<div class="someOther">...</div>
</div><!-- end of container -->
【问题讨论】:
-
一个固定元素的位置是相对于整个页面的,而不是它的父元素。