日期:2014-05-17  浏览次数:20606 次

div中float属于的奇怪现象~~(有代码)
如果需要在一个div中动态添加内容,则这个div动态改变高度大小,但是如果动态添加的内容通过 float 属性设置后,该div块的background-color 属性便会失效,请问该如何解决这个问题呢?谢谢~~

前提条件:1、该 div 必须不能指定高度 2、div块必须要设置背景色

HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#content{
    margin:50px 20px 50px; 200px;
    background-color:#999;
    display:block;
    padding: 10px;
    position: relative;
}

#d01, #d02{
    float:left;
    width:200px;
    height:200px;
    background-color:#06F;
}
#d02{
    background-color:#FF0;
}
</style>

</head>

<body>
<div id="content">
<div id="d01"></div>
<div id="d02"></div>
<div>
</body>
</html>



------解决方案--------------------
啥意思? 有代码测试不?
------解决方案--------------------
加入 "min-Height:20px " 属性即可。
div使用了 float属性,高度变为当前内容的高度,代码中没有内容所以高度为0,当然就看不见背景了