flexbox实现不等宽不等高的瀑布流布局
第一次做不等宽不等高的瀑布流布局,刚开始企图用ccs3的column属性+flexbox来实现,瞎捣鼓半天都没有能弄好,
弱鸡哭晕在厕所(┬_┬),气的午饭都没有吃.
后来逼着自己冷静下来,又捣鼓了1个小时,终于搞定了!!!长舒一口气(๑•ᴗ•๑)把代码分享给大家,希望能帮到小白:-D
-
最终效果如下:
-
html基本布局如下:
<body>
<div class="container">
<div class="box box0">
<span class="item"></span>
<div class="boxcontainer">
<div class="box box01">
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
</div>
<div class="box box02">
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
</div>
</div>
</div>
<div class="box box2">
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
</div>
<div class="box box3">
<span class="item"></span>
<span class="item"></span>
<span class="item"></span>
</div>
</div>
</body>
- css样式如下:
<style>
.container{
width: 710px;
height: 1000px;
margin: 50px auto;
background-color: #eee;
display: flex;
flex-flow:row nowrap;
justify-content:space-between;
box-sizing:border-box;
padding: 10px;
}
.box{
box-sizing:border-box;
}
.box span{
display: block;
margin-bottom: 10px;
width: 160px;
box-sizing:border-box;
}
.box0 span{
width: 330px;
height: 150px;
background-color: blue;
}
.boxcontainer{
width: 330px;
display: flex;
flex-flow:row wrap;
justify-content:space-between;
}
.boxcontainer span{
width: 160px;
background-color: orange;
}
.boxcontainer .box01 span{
height: 80px;
background-color: purple;
}
.boxcontainer .box02 span{
height: 160px;
}
.box2 span{
height: 100px;
background-color: green;
}
.box3 span{
height: 200px;
background-color: pink;
}
</style>