welcome

CSS实现瀑布流布局

 

html标签格式

<div class="box">
    <div class="item">
        <img  src="banner.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="show.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="cloth.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="banner.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="show.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="cloth.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="banner.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="show.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="cloth.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="show.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="cloth.jpg" alt="" />
    </div>
    <div class="item">
        <img  src="banner.jpg" alt="" />
    </div>
</div>

 

一、flex 弹性布局实现瀑布流

        .box {
          display: flex;  
          flex-flow:column wrap;
          height: 100vh;
        }
        .item {
            margin: 10px;
            width: calc(100%/3 - 20px);     //这里要展示几列就除于几
        }
        .item img{
            width: 100%;
            height:100%;
        }    

二、column 多行布局实现瀑布流

column 实现瀑布流主要依赖两个属性。
一个是 column-count 属性,是分为多少列。
一个是 column-gap 属性,是设置列与列之间的距离。

        .box {
            margin: 10px;
            column-count: 3;
            column-gap: 10px;
        }
        .item {
            margin-bottom: 10px;
        }
        .item img{
            width: 100%;
            height:100%;
        }

 

posted @ 2020-11-05 11:10  一首弦曲献仙音  阅读(1910)  评论(0编辑  收藏  举报
//博文图片放大缩小 //飘桃花效果