CSS容器div不获得高度 [英] CSS container div not getting height

查看:178
本文介绍了CSS容器div不获得高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的容器div得到它的孩子的高度的最大值的高度。不知道孩子 div 的高度。我正在尝试 JSFiddle 。容器 div 为红色。这不显示。为什么?

I want my container div to get the height of max of its children's height. without knowing what height the child divs 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;
}

这将强制容器尊重其中所有元素的高度,的浮动元素。

http://jsfiddle.net/gtdfY/3/

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;
}

http://jsfiddle.net/gtdfY/368/

这篇关于CSS容器div不获得高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆