我有一个父 div 和 2 个子 div,如下所示:
<div class="parent">
<div style="height:100px; float:left;" >
aaa
</div>
<div style="height:200px; float:left;">
bbb
</div>
</div>
如何设置“parent”css来适配inner div的最大高度?在这种情况下:200px
PS:height=100%
和 height=auto
都不起作用。
谢谢。
最佳答案
父 div 不占用其内容的高度,因为内部 div 是 float 的。在关闭父 div 之前,您必须清除 float 。试试这个:
<div class="parent">
<div style="height:100px; float:left;" >
aaa
</div>
<div style="height:200px; float:left;">
bbb
</div>
<div style="clear:both"></div>
</div>
编辑:您可能想查看这篇 w3c 文章以深入了解有关 float 和清除的信息:http://www.w3.org/wiki/Floats_and_clearing
关于css - 如何设置父div高度自适应内层div高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12514564/