简体   繁体   English

将父div扩展到最高定位的子项的高度

[英]Expand parent div to height of TALLEST absolutely-positioned child

I know that parent divs can't be expanded to the height of an absolutely-positioned child with pure CSS and I found one solution that addresses this with some js: http://jsfiddle.net/6csrV/7/ 我知道父div不能使用纯CSS扩展到绝对定位的子对象的高度,我找到了一种使用某些js解决此问题的解决方案: http : //jsfiddle.net/6csrV/7/

But what if you have multiple columns, each positioned absolutely, and you don't know which one will be tallest? 但是,如果您有多列,每列都绝对放置,又不知道哪一列会最高呢? For example: 例如:

<div class="parentWrapper">
    <div class="column column1">This content may be 4 lines long</div>
    <div class="column column2">This content may be 8 lines long</div>
    <div class="column column3">This content may be 5 lines long</div>
</div>

To add yet another challenge, the number of columns may also differ, so it should be possible to target the generic "column" class rather than column1, column2, column3 etc... 为了增加另一个挑战,列的数量也可能会有所不同,因此应该有可能针对通用“ column”类,而不是column1,column2,column3等。

And to make it even more of a challenge, is it possible to have this work only when the browser viewport is narrower than a specified number of pixels? 并且使其更具挑战性,是否只有在浏览器视口窄于指定像素数的情况下才能进行这项工作?

Use height:auto for the layer http://jsfiddle.net/saysiva/PuVvh/1/ 将height:auto用作图层http://jsfiddle.net/saysiva/PuVvh/1/

#container {
width:500px;
position:absolute;
left:200px;
vertical-align:center;
}

#mainContainer {
border:0px solid red;
height:auto;
}

#menu {
background-color:#FFD700;
height:auto;
width:100px;
float:left;
}

#content {
background-color:#EEEEEE;
height:auto;
width:400px;
float:left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM