[英]How do I make a overflow:scroll div have the same height of its container? Details inside
I have a website with two columns, within a wrapper div.我有一个包含两列的网站,位于包装器 div 中。
The wrapper has the same height as the tallest div by giving floating everything and giving the wrapper height:100%
.包装器具有与最高 div 相同的高度,方法是让所有内容都浮动并给包装器height:100%
。
Here's my problem: one of the columns is a div with overflow:scroll and several images in it.这是我的问题:其中一列是一个带有 overflow:scroll 和几个图像的 div。 I tried to set its height to 100%, thinking that it would take up the full height of the wrapper.我试图将它的高度设置为 100%,认为它会占据包装纸的整个高度。 Instead, it became the height of all the images on top of each other.相反,它变成了所有图像彼此叠加的高度。
If I set the height of the column with images ( #rightbox
) to a specific height in pixels, this happens.如果我将带有图像 ( #rightbox
) 的列的高度设置为以像素为单位的特定高度,就会发生这种情况。
I want it to have the same height as the other div with text, so I set its height to 100%.我希望它与另一个带有文本的 div 具有相同的高度,因此我将其高度设置为 100%。 Then this happens.然后发生这种情况。
How can I make the two columns have the same height?如何使两列具有相同的高度?
EDIT: I forgot to mention that the amount of text varies, so I can't define a specific height for the wrapper.编辑:我忘了提到文本的数量会有所不同,所以我无法为包装器定义特定的高度。
You cannot define height as 100%
unless your parents provides an actual heights.除非您的父母提供实际身高,否则您不能将身高定义为100%
。
#wrapper {
height: 800px;
}
/* Now you can make the columns inside take the full height of its parent *?
#wrapper .columns {
height: 100%;
overflow: auto;
}
Note: if the wrapper sits inside the body
element then you will need to set html,body { height: 100%; }
注意:如果包装器位于body
元素内,则需要设置html,body { height: 100%; }
html,body { height: 100%; }
before the wrapper can be set to 100%
html,body { height: 100%; }
在 wrapper 可以设置为100%
之前
Given the limited amount of code provided... here is a pure css solution.鉴于提供的代码数量有限...这里是一个纯粹的 css 解决方案。
http://jsfiddle.net/rlemon/Q7MvS/ http://jsfiddle.net/rlemon/Q7MvS/
.wrapper {
height: 600px;
width: 800px;
}
.panel {
float: left;
width: 400px;
height: 100%;
}
.panel.right {
overflow: scroll;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.