日期:2014-05-16  浏览次数:20672 次

盒子2为何消失不见????
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body
{
margin:0px}
div
{
background-color:#0F9;
width:200px;
height:100px;
}

#div1{background-color:#00F;float:left;}
#div2{background-color:#FF0;}
</style>
</head>

<body>
<div id="div1">盒子1</div>
<div id="div2">盒子2</div>
<div id="div3">盒子3</div>
</body>
</html>


显示情况如下:

------解决方案--------------------
是因为1把2挤出去了
------解决方案--------------------
#div1{background-color:#00F;float:left;} 导致盒子1浮动出文本流,所以盒子2占据原盒子1的位置,盒子1浮起覆盖盒子2但是盒子2的文字要环绕在盒子1周围,所以被挤压到下面。盒子3与盒子2的margin:0,所以盒子3把盒子2被挤压出来的文字覆盖了。所以并不是盒子2和盒子3重合,二是盒子2的文字被挤压出来后被盒子3覆盖。
可以设置边框验证下。