父级的高度设置为auto,但不会增长,因为子级div的左侧为浮点数。这是怎么回事,我该如何解决?
的HTML
<div class="wrap">
<div class="content">....</div>
</div>
的CSS
.wrap{
background: blue;
width:600px;
height: auto;
border: solid 3px;
}
.content{
background: red;
width:200px;
padding: 10px;
height: auto;
float: left;
}
您可以添加overflow:auto
到您的wrap div
或者 clear the floats.
解决方案1:
HTML:
<div class="wrap">
<div class="content">....</div>
</div>
CSS:
.wrap{
background: blue;
width:600px;
height: auto;
border: solid 3px;
overflow:auto;
}
解决方案2:
<div class="wrap">
<div class="content">....</div>
<div class="clr"></div>
</div>
CSS:
.clr
{
clear:both;
}
请参考以下链接以获得更好的理解:清除浮点数
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句