根据CSS 2.1标准,浮动元素的垂直边缘不应该与任何相邻元素折叠。浮动元素折叠边缘
参见: http://www.w3.org/TR/CSS21/box.html#collapsing-margins
但实际上,这是不是在IE6之外的所有浏览器(FF,Safari浏览器,Opera和Chrome浏览器)会发生什么(不与IE7或IE8尝试虽然)。代码如下:
<!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>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
</head>
<body>
<div style="margin-bottom:10px;">HEADER</div>
<div style="float:left;width:100%;margin:10px 0px;">Floating div</div>
<div style="margin-top:10px;">FOOTER</div>
</body>
</html>
加上clear:both;到页脚div没有任何区别。
我在CSS没有专家,所以请纠正我,如果我的理解是错误的
编辑:
显然,我的问题,造成了一些混乱。上面的代码只是为了演示我所指的行为,我试图找到解决方案并不是一个真正的问题。
感谢您的解释,实际上我怀疑同样的事情,但不确定。至于使用填充而不是边距,实际上这是我为你提到的相同原因所做的。 – 2009-04-19 15:30:03