简体   繁体   English

如何使 overflow:scroll div 与其容器具有相同的高度? 里面的细节

[英]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.

相关问题 如何使容器内的div具有与其他div兄弟同尺寸的图像? - How do i make make a div inside a container have an image that is sized like its other div siblings? 如何使div具有与其内容相同的宽度和高度? - How do I make a div have the same width and height of its content? 如何使带有溢出的外部div:auto扩展到其内容的高度到一个点? - How do I make an outer div with overflow:auto expand to the height of its contents up to a point? 使内部div与容器的高度相同 - Make the inside div same height as container 一个带孩子的Div的孩子都漂浮了:如何使Div的高度足以容纳其孩子? - A Div with Children all Floated: How do I Make the Div have Enough Height to Contain its Children? 标签位于容器内时,如何使div元素从容器中浮出 - How do I make a div element float out of its container, when the tag is inside the container 如何使TABLE成长为与其容器相同的高度? (或与IE JavaScript速度作斗争) - How do I have a TABLE grow to be the same height as its container? (or, battling IE JavaScript slowness) 如何扩展 ul 或 div 以填充其容器的高度 - how do I expand a ul or div to fill the height of its container 如何使容器div仅水平溢出而不使用“display:inline-block”作为其内部div? - How do I make a container div only overflow horizontally without using “display:inline-block” for its inner divs? 如何使div出现在容器的外部并滚动,同时保持容器的溢出 - How do I get a div to appear outside it's container, and scroll, while keeping overflow on it's container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM