纯CSS3多列的瀑布流布局演示

网上的瀑布流布局大部分都是通过JS来求定位,但现在CSS3也可以做到了,你不需要使用一点JS,就可以做出一个反应快速的CSS3瀑布流布局。

html代码:

<div class="container">
<div class="waterfall">

<div class="pin">
<img src="http://dummyimage.com/640x4:3" />
<p>1 convallis timestamp</p>
</div>

<div class="pin">
2 Donec a fermentum nisi.
</div>

<div class="pin">
<img src="http://dummyimage.com/640x3:4" />
<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>
</div>

<div class="pin">
<img src="http://loremflickr.com/640/480/germany" />
<p>
4 Donec a fermentum nisi. Integer dolor est, commodo ut
sagittis vitae, egestas at augue.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/480x4:3" />
<p>
5 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed feugiat consectetur pellentesque. Nam ac elit risus,
ac blandit dui. Duis rutrum porta tortor ut convallis.
Duis rutrum porta tortor ut convallis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/480x3:4" />
<p>
6 Nullam eget lectus augue. Donec eu sem sit amet ligula
faucibus suscipit. Suspendisse rutrum turpis quis nunc
convallis quis aliquam mauris suscipit.
Duis rutrum porta tortor ut convallis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/640x21:10" />
<p>
7 Nullam eget lectus augue.
</p>
</div>

<div class="pin">
<p>
8 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed feugiat consectetur pellentesque.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/800x4:3" />
<p>
9 Donec a fermentum nisi. Integer dolor est, commodo ut
sagittis vitae, egestas at augue. Suspendisse id nulla
ac urna vestibulum mattis. Duis rutrum porta tortor ut convallis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/900x4:2" />
<p>
10 Donec a fermentum nisi. Integer dolor est, commodo ut
sagittis vitae, egestas at augue. Suspendisse id nulla
ac urna vestibulum mattis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/640x5:4" />
<p>
11 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed feugiat consectetur pellentesque. Nam ac elit risus,
ac blandit dui. Duis rutrum porta tortor ut convallis.
</p>
</div>

<div class="pin">
<img src="http://loremflickr.com/1024/768/cool" />
<p>
12 Donec a fermentum nisi. Integer dolor est, commodo ut
sagittis vitae, egestas at augue. Suspendisse id nulla
ac urna vestibulum mattis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/800x16:3" />
<p>
13 Donec a fermentum nisi. Integer dolor est, commodo ut
sagittis vitae, egestas at augue. Suspendisse id nulla
ac urna vestibulum mattis.
</p>
</div>

<div class="pin">
<img src="http://loremflickr.com/1024/768/vw,golf,variant/all" />
<p>
14 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed feugiat consectetur pellentesque. Nam ac elit risus,
ac blandit dui. Duis rutrum porta tortor ut convallis.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/300x4:3" />
<p>
15 Nullam eget lectus augue.
</p>
</div>

<div class="pin">
<img src="http://dummyimage.com/640x16:9" />
<p>
16 Nullam eget lectus augue.
</p>
</div>
</div>
</div>

css代码:

body {
background-color: #f6f6f6;
}

.container {
width: 80%;
margin: 0 auto;
}

.waterfall {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
-moz-column-width: 24em;
-webkit-column-width: 24em;
column-width: 24em;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
}

.pin {
padding: 1em;
margin: 0 0.125em 1em;
-moz-page-break-inside: avoid;
-webkit-column-break-inside: avoid;
break-inside: avoid;
background: white;
-moz-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
-webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
}
.pin img {
width: 100%;
padding-bottom: 1em;
margin-bottom: 0.5em;
border-bottom: 1px solid #cccccc;
}

不服来看看 演示


关注我

我的微信公众号:前端开发博客,在后台回复以下关键字可以获取资源。

  • 回复「小抄」,领取Vue、JavaScript 和 WebComponent 小抄 PDF
  • 回复「Vue脑图」获取 Vue 相关脑图
  • 回复「思维图」获取 JavaScript 相关思维图
  • 回复「简历」获取简历制作建议
  • 回复「简历模板」获取精选的简历模板
  • 回复「加群」进入500人前端精英群
  • 回复「电子书」下载我整理的大量前端资源,含面试、Vue实战项目、CSS和JavaScript电子书等。
  • 回复「知识点」下载高清JavaScript知识点图谱

每日分享有用的前端开发知识,加我微信:caibaojian89 交流