简体   繁体   English

根据孩子的身高,父母div没有达到身高。

[英]Parent div is not taking height according to its children height.

Here is my code: 这是我的代码:

HTML HTML

<div id="body">
    <div id="left">a</div>
    <div id="main">b</div>
    <div id="right">c</div>
</div>

CSS: CSS:

#body {    width: 520px;    border:solid 10px #d2d2d2;}
#left { float:left;width:170px;height:200px}
#main { float:left;width:170px;height:400px}
#right { float:left;width:170px;height:200px}

Why doesnt #body surround div#left,#div#main, div#right 为什么#body不包围div#left,#div#main,div#right

If i set display : table it is ok 如果我设置display:table就可以了

Add overflow:hidden to #body css. 添加溢出:隐藏到#body css。

#body {    width: 520px;    border:solid 10px #d2d2d2; overflow:hidden;}

OR 要么

Use any class (eg clearfix) on the parent element. 在父元素上使用任何类(例如clearfix)。 Refer CSS Trick article for reference: https://css-tricks.com/snippets/css/clear-fix/ 请参阅CSS Trick文章以供参考: https//css-tricks.com/snippets/css/clear-fix/

The float property is designed to allow content to drop through the bottom of the block containing it because it is intended to be used for things such as images which multiple paragraphs should wrap around. float属性旨在允许内容通过包含它的块的底部掉落,因为它旨在用于诸如多个段落应该环绕的图像之类的内容。

See containing floats for more details and examples. 有关更多详细信息和示例,请参阅包含浮动

Set overflow: hidden on #body to cause the container to expand to contain all the floating elements inside it. 设置overflow: hidden#body以使容器展开以包含其中的所有浮动元素。 Alternatively see some other techniques . 或者看一些其他技术

Another approach, although one that doesn't work in particularly old versions of Internet Explorer is to use display: inline-block instead of float . 另一种方法,虽然在特别旧版本的Internet Explorer中不起作用的方法是使用display: inline-block而不是float

 #body { 
    overflow:hidden;
 }

Try this: 尝试这个:

<div id="body">
    <div id="left">a</div>
    <div id="main">b</div>
    <div id="right">c</div>
    <div style="clear:both;"></div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM