我有一个带有垂直滚动的布局。可滚动的div中有一个绝对定位的子元素,它具有大的top值,在父级上引起了垂直滚动条。
可滚动的父div还有一些子div元素(我们称之为柱子),通过position: absolute和一些left值水平相邻地定位在一起。
以下是HTML标记:
<div id="root" style="height: 250px; position: relative;">
<div class="stretch">
<div id="container" class="container">
<div id="pillar1" style="left: 0.0%; width:33.25%;" class="pillar" ></div>
<div id="pillar2" style="left: 33.05%; width:33.25%;" class="pillar" ></div>
<div id="pillar3" style="left: 66.05%; width:33.25%;" class="pillar" ></div>
<div id="fixed-and-not-movable" style="background: blue; width: 25px; height: 25px; top:350px; left: 150px; position: absolute;">
</div>
</div>
以及 CSS:
.stretch {
bottom: 0;
left: 0;
right: 0;
top: 0;
position: absolute;
height: auto;
width: auto;
}
.container {
border: 2px solid;
bottom: 0;
left: 0;
right: 0;
top: 0;
overflow-x: hidden;
overflow-y: scroll;
position: absolute;
}
.pillar {
border: 1px dotted red;
bottom: 0;
height: 100%;
position: absolute;
top: 0;
}
我希望柱形div可以捕获父元素“container”的整个滚动高度。目前它们的高度是父元素的客户端高度(而不是滚动高度)。因此,当您向下滚动时,您会注意到柱体没有填充溢出:滚动内所有可用的高度。
有人能建议更改CSS类(.container
和/或.pillar
)以使其生效吗?
这里有一个链接到js fiddle演示相同问题: http://jsfiddle.net/AshwinPrabhuB/2o5whkmq
谢谢!