我的 html/css 代码在这里需要一点帮助...我需要跟随我的 divbody 的高度到 divwrapper,因为 divwrapper 向左浮动,我的 divbody 的高度只有 10(有填充值5 像素)。这是代码,谢谢!
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Information Technology</title>
</head>
<style>
body{
margin:0px;
}
.divbody{
width:970px;
height:auto;
background-color:#cecece;
margin:0px auto;
padding:5px;
}
.divwrapper{
height:auto;
background-color:#eee;
float:left;
padding:5px;
}
.divcontent{
width:480px;
height:200px;
background-color:yellow;
float:left;
border-bottom:1px solid #000;
}
</style>
<body>
<div class="divbody">
<div class="divwrapper">
<div class="divcontent">
</div>
<div class="divcontent">
</div>
</div>
</div>
</body>
最佳答案
使用 clearfix 方法解决 float 问题。
HTML
<div class="divbody clearfix">
<div class="divwrapper">
<div class="divcontent">
</div>
<div class="divcontent">
</div>
</div>
</div>
CSS
body{
margin:0px;
}
.divbody{
width:970px;
height:auto;
background-color:#cecece;
margin:0px auto;
padding:5px;
}
.divwrapper{
height:auto;
background-color:#eee;
float:left;
padding:5px;
}
.divcontent{
width:480px;
height:200px;
background-color:yellow;
float:left;
border-bottom:1px solid #000;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
关于html - Div 高度 HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17613569/