为什么后面那个div覆盖前面div 如果后面也加float:left 就不覆盖了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#divmain{
margin:0 auto;
width:470px;
}
#div1{
float:left;
width:100px;
height:100px;
background:#006;
}
#div2{
width:100px;
height:100px;
background:#CCC;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div id="divmain">
<div id="div1">10</div>
<div id="div2">20</div>
</div>
</body>
</html>
float:left; HTML css div
[解决办法]
以后代码要用代码框编辑,要不然这样人家看也不方便。
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#divmain{
margin:0 auto;
width:470px;
background:#999;
}
#div1{
float:left;
margin:0 auto 0 20px;
width:100px;
height:100px;
background:#fff;
/* z-index=-1;*/
}
#div2{
width:100px;
height:100px;
background:#CCC;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div id="divmain">
52345623546
<div id="div1">10</div>
<div id="div2">20345345</div>
</div>
</body>
</html>