我有页面结构为:

<div class="parent">
    <div class="child-left floatLeft">
    </div>

    <div class="child-right floatLeft">
    </div>
</div>

现在,左子DIV将有更多的内容,因此父DIV的高度会随着子DIV的增加而增加。

但问题是适合儿童的身高并没有增加。如何让它的高度等于它的父结点?


当前回答

<div class="parent" style="height:500px;">
<div class="child-left floatLeft" style="height:100%">
</div>

<div class="child-right floatLeft" style="height:100%">
</div>
</div>

我使用内联样式只是为了表达想法。

其他回答

我在评论区用了这个:

.parent { display: flex; float: left; border-top:2px solid black; width:635px; margin:10px 0px 0px 0px; padding:0px 20px 0px 20px; background-color: rgba(255,255,255,0.5); } .child-left { align-items: stretch; float: left; width:135px; padding:10px 10px 10px 0px; height:inherit; border-right:2px solid black; } .child-right { align-items: stretch; float: left; width:468px; padding:10px; } <div class="parent"> <div class="child-left">Short</div> <div class="child-right">Tall<br>Tall</div> </div>

您可以将child-right浮动到右边,但在这种情况下,我已经精确地计算了每个div的宽度。

对于父节点:

display: flex;

儿童:

align-items: stretch;

你应该添加一些前缀,检查caniuse。

请将父div设置为overflow: hidden 然后在儿童潜水你可以设置大量填充底部。例如 padding-bottom: 5000像素 然后margin-bottom: -5000px 然后所有子div都是父节点的高度。 当然,这不会工作,如果你试图把内容放在父div(外面的其他div是)

.parent{ border: 1px solid black; overflow: hidden; height: auto; } .child{ float: left; padding-bottom: 1500px; margin-bottom: -1500px; } .child1{ background: red; padding-right: 10px; } .child2{ background: green; padding-left: 10px; } <div class="parent"> <div class="child1 child"> One line text in child1 </div> <div class="child2 child"> Three line text in child2<br /> Three line text in child2<br /> Three line text in child2 </div> </div>

例如:http://jsfiddle.net/Tareqdhk/DAFEC/

<div class="parent" style="height:500px;">
<div class="child-left floatLeft" style="height:100%">
</div>

<div class="child-right floatLeft" style="height:100%">
</div>
</div>

我使用内联样式只是为了表达想法。

如果你了解bootstrap,你可以通过使用'flex'属性轻松完成。你所需要做的就是将下面的css属性传递给父div

.homepageSection {
  overflow: hidden;
  height: auto;
  display: flex;
  flex-flow: row;
}

其中。homepagesection是我的父div。 现在在你的html中添加子div

<div class="abc col-md-6">
<div class="abc col-md-6">

abc是我的子div,你可以检查两个子div的高度相等,而不考虑边界,只要给子div边界