解决高度坍塌和外边距重叠问题
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
/* 解决高度塌陷和外边距重叠问题clearfix */
.clearfix::before,
.clearfix::after{
content:" ";
display:table;
clear:both;
}
/* 外边距重叠也可以直接给父元素设置overflow:hidden */
.box1{
width: 400px;
height: 400px;
background-color: #0000FF;
}
.box2{
width: 200px;
height: 200px;
background-color: #9932CC;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="box1 clearfix">
<div class="box2"></div>
</div>
</body>
</html>