生成包含浮动嵌套div的父div的高度 [英] Grow height of parent div that contains floating nested divs

查看:120
本文介绍了生成包含浮动嵌套div的父div的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法自动增长我的父div的高度基于其浮动子div。所有的孩子都是浮动的,水平地占据空间,然后包装到下一行。可以有不断变化的浮动子节点数,父节点必须自动调整其高度。 (父div用作所有浮动div的背景)。在父div下面还有一个div,需要向下压,以便它在浮动div下面。

I can't seem to auto-grow my parent div's height based on its floating child divs. All the children are floating, to take up space horzontally, and then wrapping to the next line. There can be a changing number of floating children, and the parent has to autosize its height. (The parent div serves as a background for all the floating divs). There is also a second div below the parent div that needs to be pushed down so that it is below the floating divs.

这个解决方案在IE中很重要。

It's of major importance that the solution works in IE.

推荐答案

您可以插入一个div,用于清除最后一个子元素之后的浮动广告。

You could insert a div that clears the floaters after the last child.

HTML:

<div style="clear: both"></div> <!-- This goes after the last floated element - no floating elements are allowed on either side of this. -->

fiddle: http: //jsfiddle.net/Rc5J8/

这篇关于生成包含浮动嵌套div的父div的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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