垂直方向外边距塌陷

未处理前
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
/* 方案1: 给外边的大盒子使用overflow:hidden; */
/* .father {
width: 500px;
height: 300px;
background: #eee;
overflow: hidden;
} */
/* 方案2: 给外边的大盒子定义边框 */
.father {
width: 500px;
height: 299px;
border-top: 1px solid #eee;
background: #eee;
}
.son {
width: 100px;
height: 100px;
background: red;
margin-top: 50px;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>

处理后
本文标题:垂直方向外边距塌陷
本文链接:https://www.haomeiwen.com/subject/tmzakktx.html
网友评论