CSS3實現瀑布流布局的方法

來源:互聯網
上載者:User
這次給大家帶來CSS3實現瀑布流布局的方法,CSS3實現瀑布流布局的注意事項有哪些,下面就是實戰案例,一起來看一下。

以前使用瀑布流都要用js,現在有了css3,可以輕鬆實現了。

掌握點:

1、column-count 把p中的文本分為多少列

2、column-width 規定列寬

3、column-gap 規定列間隙

4、break-inside: avoid; 避免元素內部斷行併產生新列

注意: Internet Explorer 9及更早 IE 版本瀏覽器不支援 column-count 屬性。

column-count 屬性規定元素應該被分隔的列數:

p{-moz-column-count:3;  /* Firefox */-webkit-column-count:3; /* Safari 和 Chrome */column-count:3;}

column-gap 屬性規定列之間的間隔:

p{-moz-column-gap:40px;  /* Firefox */-webkit-column-gap:40px; /* Safari 和 Chrome */column-gap:40px;}

column-rule 屬性設定列之間的寬度、樣式和色彩規則:

p{-moz-column-rule:3px outset #ff0000; /* Firefox */-webkit-column-rule:3px outset #ff0000; /* Safari and Chrome */column-rule:3px outset #ff0000;}

執行個體:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>CSS3瀑布流</title>    <style>    /*大層*/    .container{width:80%;margin: 0 auto;}    /*瀑布流層*/    .waterfall{        -moz-column-count:4; /* Firefox */        -webkit-column-count:4; /* Safari 和 Chrome */        column-count:4;        -moz-column-gap: 1em;      -webkit-column-gap: 1em;      column-gap: 1em;    }    /*一個內容層*/    .item{      padding: 1em;      margin: 0 0 1em 0;      -moz-page-break-inside: avoid;      -webkit-column-break-inside: avoid;      break-inside: avoid;     border: 1px solid #000;    }    .item img{        width: 100%;        margin-bottom:10px;    }    </style></head><body>    <p class="container">        <p class="waterfall">            <p class="item">                <img src="https://imgsa.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign=f3d4063328738bd4d02cba63c0e2ecb3/a2cc7cd98d1001e910616de1be0e7bec55e797fa.jpg">                <p>1 convallis timestamp</p>           </p>            <p class="item">                <img src="https://imgsa.baidu.com/baike/c0%3Dbaike92%2C5%2C5%2C92%2C30/sign=03948ea9b4315c60579863bdecd8a076/8326cffc1e178a825a6b5d1cfe03738da977e833.jpg">                <p>2 convallis timestamp 2 Donec a fermentum nisi. </p>           </p>            <p class="item">                <img src="https://imgsa.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=3d645bf2d0ca7bcb6976cf7ddf600006/6d81800a19d8bc3efe5f64fb858ba61ea8d345af.jpg">                <p>3 Nullam eget lectus augue. Donec eu sem sit amet ligula         faucibus suscipit. Suspendisse rutrum turpis quis nunc         convallis quis aliquam mauris suscipit.</p>           </p>            <p class="item">                <img src="https://imgsa.baidu.com/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=fbc3501b0a087bf469e15fbb93ba3c49/bf096b63f6246b60ea65dd24e3f81a4c510fa273.jpg">                <p> 4 Donec a fermentum nisi. Integer dolor est, commodo ut         sagittis vitae, egestas at augue. </p>           </p>  <p class="item">                <img src="https://imgsa.baidu.com/baike/c0%3Dbaike150%2C5%2C5%2C150%2C50/sign=9fe1d71697ef76c6c4dff379fc7f969f/b03533fa828ba61ed2efcd184634970a304e5987.jpg">                <p> 5 Donec a fermentum nisi. Integer dolor est, commodo ut sagittis vitae, egestas at augue.</p>           </p>        </p>    </p></body></html>

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

CSS3做出條紋大背景

css3文字漸層動畫

CSS3的滑鼠移入圖片動態提示效果

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.