<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<title>解决高度塌陷与外边距重叠的方法</title>
<link rel="stylesheet" href="css/reset.css">
<style>
.clearfix:before,
.clearfix:after{
content: '';
display: table;
clear: both;
} /*这个是核心代码*/
.clearfix{
width: 200px;
height: 200px;
background-color: #1bc4fb;
}
.box{
width: 100px;
height: 100px;
background-color: #f97053;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="clearfix">
<div class="box"></div>
</div>
</body>
</html>
reset.css
结果展示: