小注意,这只能在 Firefox 和 chrome 中实现。CSS 中的纯砌体布局根本不可能。对于 Internet Explorer 后退查看 packery:http ://packery.metafizzy.co/
编辑:如果你所有的盒子都有相同的高度:然后添加 float:left 到每个盒子
演示: http: //jsfiddle.net/gabrieleromanato/tQANc/
演示 V2: http: //jsfiddle.net/umbriel/TzkZ8/
演示 V3 IE 兼容:http: //jsfiddle.net/umbriel/6e6Qy/
HTML:
<div id="container" class="cols">
<div class="box one"></div>
<div class="box two"></div>
<div class="box one"></div>
<div class="box three"></div>
<div class="box two"></div>
<div class="box five"></div>
<div class="box one"></div>
<div class="box two"></div>
<div class="box six"></div>
<div class="box three"></div>
<div class="box two"></div>
</div>
CSS:
#container {
width: 100%;
max-width: 700px;
margin: 2em auto;
}
.cols {
-moz-column-count:3;
-moz-column-gap: 3%;
-moz-column-width: 30%;
-webkit-column-count:3;
-webkit-column-gap: 3%;
-webkit-column-width: 30%;
column-count: 3;
column-gap: 3%;
column-width: 30%;
}
.box {
margin-bottom: 20px;
}
.box.one {
height: 200px;
background-color: #d77575;
}
.box.two {
height: 300px;
background-color: #dcbc4c;
}
.box.three {
background-color: #a3ca3b;
height: 400px;
}
.box.four {
background-color: #3daee3;
height: 500px;
}
.box.five {
background-color: #bb8ed8;
height: 600px;
}
.box.six {
background-color: #baafb1;
height: 200px;
}