【发布时间】:2017-09-06 07:06:24
【问题描述】:
我有一个绝对定位的 div 和两个孩子——一个绝对定位的 div 和一个将在父级内滚动的静态 div。它看起来像这样:
<div class='frame'>
<div class='absolute-contents'>This should stay put.</div>
<div class='static-contents'>This should scroll under it.</div>
</div>
这是 CSS:
.frame {
position: absolute;
top: 40px;
left: 40px;
right: 40px;
bottom: 40px;
overflow-y: scroll;
}
.absolute-contents {
position: absolute;
top: 40px;
left: 40px;
right: 40px;
bottom: 40px;
z-index: 9999;
opacity: .9;
padding: 40px;
}
.static-contents {
margin: 24px auto;
width: 400px;
height: 3000px;
padding: 40px;
}
我的绝对子级被限制在父级的边缘,为什么它仍然滚动,我怎样才能让它保持原样?
【问题讨论】:
-
你试过
position: fixed;了吗? -
是的。但我希望它固定在父窗口中,而不是整个窗口。