0
点赞
收藏
分享

微信扫一扫

上下外边距合并


当两个容器,一个有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


举报

相关推荐

CSS 外边距合并、塌陷和BFC

外边距合并问题及解决方案

0 条评论