我的页面中有3个元素。它们分别是外部、中间和内部。
html代码:
<div class="outer">
<div class="middle">
<div class="inner">
inner suppose to stay at the bottom of the outer.
</div>
</div>
</div>css代码:
.outer {
position: fixed;
top: 20px;
max-width: 400px;
background: red;
height: 400px;
overflow: auto;
width: 200px;
}
.middle {
width: 100%;
height: 800px;
padding: 100px 0;
position: static;
background: green;
}
.inner {
width: 100%;
position: absolute;
height:100px;
background: yellow;
bottom: 0
}我认为内部应该留在外部的底部。然而,我没有。有人能告诉我为什么吗?
发布于 2016-06-22 17:13:50
我已经做到了这一点,问题是内部的宽度,不能使用100%,因为重叠滚动条。我的设置是184px,在我的电脑上使用Chrome和Firefox运行得很好,但可能在其他浏览器或其他浏览器上并不是最好的:
.dummy {
position: relative;
width: 200px;
}
.outer {
max-width: 400px;
background: red;
height: 300px;
overflow: auto;
width: 200px;
}
.middle {
width: 100%;
height: 800px;
padding: 100px 0;
background: green;
}
.inner {
width: 184px;
position: absolute;
height: 100px;
background: yellow;
bottom: 0;
}<div class="dummy">
<div class="outer">
<div class="middle">
<div class="inner">
inner suppose to stay at the bottom of the outer.
</div>
</div>
</div>
</div>
https://stackoverflow.com/questions/37962658
复制相似问题