我以为我了解 clearfix 的用途。但它可以在没有clearfix 的情况下正常工作。这是为什么?
这是我的 HTML:
<body>
<div class="clearfix">
<h1>Title</h1>
<h2>Headline 1 with a very long title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h2>Headline 1 with a very long title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<h2>Headline 2</h2>
<ul>
<li>bullet 1</li>
<li>bullet 2</li>
</ul>
</div>
</body>
和 CSS:
* {
/* basic resets */
margin: 0px;
padding: 0px;
/* font stuff */
font-family: Cambria;
font-size: 18px;
line-height: 24px;
border-color: black;
}
body, html {
margin: auto;
max-width: 700px;
}
p {
margin-left: 200px;
margin-bottom: 18px;
}
h1 {
margin-left: 200px;
}
h2 {
max-width: 150px;
margin-left: 50px;
margin-left: 0px;
float: left;
}
ul {
margin-left: 200px;
}
/*.clearfix {
overflow: auto;
zoom: 1;
}*/
这就是我得到的(这就是我想要的):
为什么没有clearfix 一切都很好?