JSFiddle - React, Tailwind, and code Playground
by wukong
HTML
<div class="out">
<div class="flex">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
<div class="bottom">
下面的元素
</div>
CSS
.out{
padding: 20px;
border: 1px solid #e5e5e5;
}
.flex {
width: 300px;
display: flex;
flex-wrap: wrap;
/* 虽然border还占据空间,但是dom上已经被-margin抵消掉了,下面的蓝色元素以及在正常排列,没有收到margin的影响 */
border: 1px solid blue;
/* 关键这句 */
margin-bottom: -50px;
overflow: hidden;
}
.box {
width: 100px;
height: 100px;
border: 1px solid red;
background: orange;
box-sizing: border-box;
margin-bottom: 50px;
}
.bottom{
width: 100px;
height: 100px;
background: lightblue;
}