純css瀑布流布局

css中有幾種瀑布流的布局,我這里使用的是column的多列布局,效果如下

效果圖

這邊主要得技術(shù)就只有三句,在父容器的

column-count: 4;  //想要分割的列數(shù)
 column-gap: 10%; //每列的邊距

和在子容器的

 break-inside: avoid;  
 // auto  指定既不強(qiáng)制也不禁止元素內(nèi)的頁(yè)/列中斷。
 // avoid  指定避免元素內(nèi)的分頁(yè)符。
 // avoid-page  指定避免元素內(nèi)的分頁(yè)符。
 // avoid-column 指定避免元素內(nèi)的列中斷。
 // avoid-region  指定避免元素內(nèi)的區(qū)域中

下面的完整的代碼(我是把它寫在了vue的組件里了,大家不用管我這個(gè)數(shù)據(jù)渲染形式,主要的是那個(gè)css)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue</title>
    <!-- vue cdn引用-->
<script type="text/javascript" src="https://unpkg.com/vue"></script>
    <style>
        .textBox{
            width: 500px;
            margin: 100px auto;
            column-count: 4;
            column-gap: 10%;
        }
        .hBox{
            break-inside: avoid;
            width: 130px;
            margin-bottom: 5px;
            border: 1px solid #ccc;
            text-align: center;
        }
    </style>
</head>

<body>

<div id="app">
    <column-grop :harr = 'harr'></column-grop>
</div>

<script>
    const VM = new Vue({
        el:'#app',
        data:{
            harr:['70','80','185','62','90','100','75','162','88','97','86','180']
        },
        components:{
            columnGrop:{
                props:['harr'],
                template:`
                    <div class="textBox">
                        <div class="hBox" v-for="h in harr" :key="h" :style="{height:h + 'px',lineHeight:h + 'px'}">{{h}}</div>
                    </div>
                `
            }
        }
    })

</script>
</body>
</html>
愛心發(fā)射biu.gif
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容