上下外边距合并

阅读 150

2022-11-19


当两个容器,一个有margin-top 一个含有margin-bottom时,两者之间的距离为,两者之间的最大值,而非两者之和。所以设置时,尽量设置一个,避免上下外边距合并的问题。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.top,
.bottom {
width: 200px;
height: 200px;
background-color: pink;
}
.top {
margin-bottom: 100px;
}
.bottom {
background-color: purple;
margin-top: 50px;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="bottom"></div>
</body>
</html>

上下外边距合并_html5


精彩评论(0)

0 0 举报