当我将其高度设置为自动时,#container 的背景颜色不显示。但是当我将其设置为 1000 像素等固定高度时,它确实会显示出来。我试过“溢出:自动”,但没有用。我该如何解决?我确实希望#container 根据其内容垂直扩展,并且我也想显示其背景颜色。任何想法将不胜感激!
这是HTML:
<div id="container">
<div id="main">
<div id="div1">text text text text text text text text text text text texttexttext text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text</div>
<div id="div2">text text text text text text text text text text text texttexttext</div>
<div class="clear"></div>
</div><!--end of main-->
</div><!--end of container-->
这是CSS:
#container {
background-color: rgb(255, 102, 204);
height: auto;
width: 1200px;
position: absolute;
}
#container #main {
background-color: rgb(204, 51, 0);
height: auto;
width: 900px;
position: absolute;
overflow: auto;
}
#container #main #div1 {
background-color: rgb(0, 204, 255);
float: left;
width: 300px;
padding: 5px;
height: auto;
margin: 20px;
}
#container #main #div2 {
background-color: rgb(0, 153, 153);
height: auto;
width: 400px;
float: left;
margin: 10px;
}
.clear {
clear: both;
}