<!DOCTYPE html>
<html lang="en">
<head>
<style>
.box1{
background-color: red;
margin-right: 100px;
}
.box2{
background-color: green;
margin-left: 100px;
}
.dome1{
background-color: yellow;
margin-bottom: 100px;
}
.dome2{
background-color: blue;
margin-top: 100px;
}
.wrapper{
overflow: hidden;
/*虽然可以使用触发BFC规则类解决这个问题,但是,这个bug我们不去解决*/
/*因为不能为了解决这个问题,随便加个wrapper*/
/*设置 margin 设置两倍的值就可以了*/
}
</style>
<meta charset="UTF-8">
<title>margin上下可共用</title>
</head>
<body>
<span class="box1">box1</span>
<span class="box2">box2</span>
<div class="dome1">dome1</div>
<div class="dome2">dome2</div>
<!-- div.test${$}*5 -->
<div class="test1">1</div>
<div class="test2">2</div>
<div class="test3">3</div>
<div class="test4">4</div>
<div class="test5">5</div>
<div class="wrapper">
<div class="dome1">dome1</div>
</div>
<div class="wrapper">
<div class="dome2">dome2</div>
</div>
</body>
</html>
网友评论