I wrote the following code and tried placing three left floated divs in a father containing div. For some reason, the body tag seems to have a ghost top margin, which is a property not defined in my code. However, if I remove the margin-bottom property of the containing div or apply a clearfix style to it, the top margin is gone. What causes the ghost top margin and how to fix it? Thx!
Check the screenshots below:
Original code:
Margin-bottom
removed:- Clearfix style applied:
This the original code:
<?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>
Original code preview:http://jsfiddle.net/qv8ph0gw/