容器DIV中的固定高度和100%高度
我试图让一个 div 延伸到 100% 高度,同时滚动条的底部仍然可见,同时也包含固定高度的 div。有人可以帮我吗:)
当使用波纹管布局时,.div2 底部的垂直滚动条会脱离视点的高度,我猜是因为 .div1 的高度为 200px,将 div1 推至 100% 高度+ 200 像素。
有没有办法让 .div1 固定高度,而 .div2 延伸以填充剩余的窗口高度并在达到该高度时溢出。
这是 CSS
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
overflow:hidden;
}
.container
{
height:100%;
}
.leftContent {
left:0;
top:0;
padding:0;
width:250px;
height:100%;
color:white;
background:blue;
overflow:hidden;
border:blue solid;
}
.div1
{
height:200px;
background-color:black;
border: red solid;
}
.div2
{
overflow:scroll;
height:100%;
border:yellow solid;
}
,这是 HTML。
<div id="container" class="container">
<!-- Start Left Column-->
<div id="leftColumn" class="leftContent">
<div id="div1" class="div1">
CONTENT
</div>
<div id="div2" class="div2">
START START START START START START START START START START START START START START START START
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
END END END END END END END END END END END END END END END END END END END END END END END END
</div>
</div>
<!-- End Left Column-->
</div>
非常感谢。 谢谢
I'm trying to get a div to extend to 100% height with the bottom of the scroll bar still visible, when also contained with a fixed height div. Can someone please help me out :)
When using the bellow layout, the vertical scroll bar at the bottom of .div2 falls off the height of the viewpoint, i'm guessing because .div1 is 200px high, pushing div1 to be 100% height + 200px.
Is there a way i can have .div1 be fixed height, and .div2 extend to fill the remaining window height and overflow when that height is reached.
Here is the CSS
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
overflow:hidden;
}
.container
{
height:100%;
}
.leftContent {
left:0;
top:0;
padding:0;
width:250px;
height:100%;
color:white;
background:blue;
overflow:hidden;
border:blue solid;
}
.div1
{
height:200px;
background-color:black;
border: red solid;
}
.div2
{
overflow:scroll;
height:100%;
border:yellow solid;
}
And here is the HTML.
<div id="container" class="container">
<!-- Start Left Column-->
<div id="leftColumn" class="leftContent">
<div id="div1" class="div1">
CONTENT
</div>
<div id="div2" class="div2">
START START START START START START START START START START START START START START START START
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT
END END END END END END END END END END END END END END END END END END END END END END END END
</div>
</div>
<!-- End Left Column-->
</div>
Much appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试对 .div2 设置
这种方式,将
.div2
放置在.div1
的正下方,使用绝对定位,并按照您想要的方式扩展其宽度和高度(达到容器)编辑
IE bug 可以通过将
.div2
包装到另一个 div 中来修复 ->也尝试将此 css 添加到您的
.leftContent
声明中Try this setup for .div2
this way you place
.div2
right under.div1
with absolute positioning and extend its width and height just like you want (to the width and height of the container)edit
IE bug can be fixed by wrapping the
.div2
into another div -><div><div class="div2"></div></div>
also try adding this css to your
.leftContent
declaration更新以下 css
使左侧内容相对,使其成为定位元素,并且现在是两个 div 的包含块。这对于允许 div2 填充剩余空间非常重要。
显式设置
border-width
以便我知道 div2 的位置不与 div1 的边框重叠。基本上使用绝对定位来让 div2 填充 leftContent 中的剩余空间,并显式指定定位。如果我使用了overflow,我会在底部看到一个不滚动的滚动条,因此我使用了overflow-y来摆脱它。
Update the following css
Made the left content relative so it becomes a positioned element and is now the containing block for the two divs. This is important to allow div2 to fill the remaining space.
Set the
border-width
explicitly so I know where to position div2 to not overlap the border of div1.Basically used absolute positioning to get div2 to fill the remaining space in leftContent along with explicitly specifying the positioning. If I used
overflow
I would get a scroll bar at the bottom that didn't scroll so to get rid of that I usedoverflow-y
.