【发布时间】:2016-02-22 08:40:45
【问题描述】:
我编写了以下代码并尝试将三个左浮动 div 放在包含 div 的父亲中。出于某种原因,body 标签似乎有一个幽灵上边距,这是我的代码中未定义的属性。但是,如果我删除包含 div 的 margin-bottom 属性或对其应用 clearfix 样式,则上边距消失了。是什么导致重影上边距以及如何解决?谢谢!
查看下面的截图:
这是原代码:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
html {
font: 16px/2 Tohoma, Verdana, Arial, Sans-serif, 'Microsoft YaHei';
background: #ccc;
}
body {
margin: 0;
padding: 0;
}
.clear-fix:after {
content: '';
display: block;
clear: both;
}
#wrap {
margin: 0 auto;
width: 1000px;
min-height: 800px;
background: #fff;
}
#header {
margin-bottom: 20px;
}
.first, .second, .third {
float: left;
padding: 20px;
min-height: 100px;
}
.first {
background: gray;
}
.second {
background: blue;
}
.third {
background: yellow;
}
</style>
<title>
Another Web Page
</title>
</head>
<body>
<div id="wrap">
<div id="header">
<div class="first">This is the first floating division</div>
<div class="second">This is the second floating division</div>
<div class="third">This is the third floating division</div>
</div>
</div>
</body>
</html>
【问题讨论】: