【发布时间】:2013-08-15 07:19:15
【问题描述】:
当我们在外部 div 上有边框时,我可以理解下面的第一个示例。 边距折叠,所以我们只得到 20px 边距。
但是第二个例子看起来很奇怪,当我们刚刚
从外部 div 中删除边框
/*Fist example */
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>"float: left" with no width set</title>
<style type="text/css" media="screen">
body
{
padding: 0;
margin:1px;
}
</style>
</head>
<body>
<div style="background-color: yellow; border: solid 1px #ccc;">
<div style="margin: 20px; background-color: red;">
<p style="margin: 20px; color:#fff; background-color: blue;">A paragraph
with a 20px margin inside a div, also with a 20px margin</p>
</div>
</div>
</body>
</html>
/* Secod example without a border on the outer div */
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>"float: left" with no width set</title>
<style type="text/css" media="screen">
body
{
padding: 0;
margin:1px;
}
</style>
</head>
<body>
<div style="background-color:yellow;">
<div style="margin: 20px; background-color: red;">
<p style="margin: 20px; color:#fff; background-color: blue;">
A paragraph with a 20px margin inside a div, also with a 20px margin
</p>
</div>
</div>
</body>
</html>
//Tony
【问题讨论】:
-
第二个示例中是否应该出现语法错误?浮动设置在标签之外