码迷,mamicode.com
首页 > Web开发 > 详细

纯css3实现瀑布流布局

时间:2017-11-29 18:22:14      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:net   htm   sci   纯css   width   实现   ndis   nta   int   

以前使用瀑布流都要用js,现在有了css3,可以轻松实现了。

掌握点:

1、column-count 把div中的文本分为多少列

2、column-width 规定列宽

3、column-gap 规定列间隙

4、break-inside: avoid; 避免元素内部断行并产生新列

注意: Internet Explorer 9及更早 IE 版本浏览器不支持 column-count 属性。

 

实例:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>CSS3瀑布流</title>
 6     <style>
 7     /*大层*/
 8     .container{width:80%;margin: 0 auto;}
 9     /*瀑布流层*/
10     .waterfall{
11         -moz-column-count:4; /* Firefox */
12         -webkit-column-count:4; /* Safari 和 Chrome */
13         column-count:4;
14         -moz-column-gap: 1em;
15       -webkit-column-gap: 1em;
16       column-gap: 1em;
17     }
18     /*一个内容层*/
19     .item{
20       padding: 1em;
21       margin: 0 0 1em 0;
22       -moz-page-break-inside: avoid;
23       -webkit-column-break-inside: avoid;
24       break-inside: avoid;
25      border: 1px solid #000;
26     }
27     .item img{
28         width: 100%;
29         margin-bottom:10px;
30     }
31     </style>
32 </head>
33 <body>
34     <div class="container">
35         <div class="waterfall">
36             <div class="item">
37                 <img src="https://imgsa.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign=f3d4063328738bd4d02cba63c0e2ecb3/a2cc7cd98d1001e910616de1be0e7bec55e797fa.jpg">
38                 <p>1 convallis timestamp</p>
39            </div>
40 
41 
42 
43             <div class="item">
44                 <img src="https://imgsa.baidu.com/baike/c0%3Dbaike92%2C5%2C5%2C92%2C30/sign=03948ea9b4315c60579863bdecd8a076/8326cffc1e178a825a6b5d1cfe03738da977e833.jpg">
45                 <p>2 convallis timestamp 2 Donec a fermentum nisi. </p>
46            </div>
47 
48 
49 
50 
51             <div class="item">
52                 <img src="https://imgsa.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=3d645bf2d0ca7bcb6976cf7ddf600006/6d81800a19d8bc3efe5f64fb858ba61ea8d345af.jpg">
53                 <p>3 Nullam eget lectus augue. Donec eu sem sit amet ligula 
54         faucibus suscipit. Suspendisse rutrum turpis quis nunc 
55         convallis quis aliquam mauris suscipit.</p>
56            </div>
57 
58 
59 
60             <div class="item">
61                 <img src="https://imgsa.baidu.com/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=fbc3501b0a087bf469e15fbb93ba3c49/bf096b63f6246b60ea65dd24e3f81a4c510fa273.jpg">
62                 <p> 4 Donec a fermentum nisi. Integer dolor est, commodo ut 
63         sagittis vitae, egestas at augue. </p>
64            </div>
65 
66   <div class="item">
67                 <img src="https://imgsa.baidu.com/baike/c0%3Dbaike150%2C5%2C5%2C150%2C50/sign=9fe1d71697ef76c6c4dff379fc7f969f/b03533fa828ba61ed2efcd184634970a304e5987.jpg">
68                 <p> 5 Donec a fermentum nisi. Integer dolor est, commodo ut sagittis vitae, egestas at augue.</p>
69            </div>
70         </div>
71     </div>
72 </body>
73 </html>

 

纯css3实现瀑布流布局

标签:net   htm   sci   纯css   width   实现   ndis   nta   int   

原文地址:http://www.cnblogs.com/skyeming/p/7921647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!