当子div浮动时,父divs失去自动填充高度 [英] When child divs are floated, parent divs lose auto-height

查看:167
本文介绍了当子div浮动时,父divs失去自动填充高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为main的父级div。它有一堆的子div,它是我向左或向右漂浮的。



当我完成最后一个漂浮时,主div的高度完全消失,关闭我的页面布局。我给它一个高度:100%;就目前而言,但在大多数分辨率上它会过高。我怎样才能将它保持在一个流畅的高度,只需要包含这些元素呢? 解决方案

包含你的浮动元素。 / p>

在div上调用main添加 overflow:hidden; 。这应该包含它。


I have a parent div called main. It has a bunch of child divs in it, which I floated left or right.

When I finished floating the last one, the height of the main div completely vanished, throwing off the layout of my page. I gave it a height:100%; just for now, but it will be overly tall on most resolutions. How can I keep it at a fluid height, only as much as needed to contain the elements?

解决方案

Contain your floats.

On the div called main add overflow:hidden;. That should contain it.

这篇关于当子div浮动时,父divs失去自动填充高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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