问题描述
我想让我的容器div得到它的孩子的高度的最大值的高度。不知道孩子 div
的高度。我正在尝试。容器 div
为红色。这不显示。为什么?
I want my container div to get the height of max of its children's height. without knowing what height the child div
s are going to have. I was trying out on JSFiddle. The container div
is on red. which is not showing up. Why?
推荐答案
添加以下属性:
.c{
...
overflow: hidden;
}
这将强制容器尊重其中所有元素的高度,的浮动元素。
This will force the container to respect the height of all elements within it, regardless of floating elements.
http://jsfiddle.net/gtdfY/3/
最近,我正在开发一个需要这个技巧的项目,但需要允许溢出显示,因此相反,您可以使用伪元素清除浮动,有效地实现相同的效果,同时允许所有元素溢出。
Recently, I was working on a project that required this trick, but needed to allow overflow to show, so instead, you can use a pseudo-element to clear your floats, effectively achieving the same effect while allowing overflow on all elements.
.c:after{
clear: both;
content: "";
display: block;
}
这篇关于CSS容器div不获得高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!