您可以使用column-count
和column-gap
CSS 属性。Mozilla 和 Webkit 都需要前缀,IE10 和 Opera 不需要。但是,IE<=9 根本不支持。
就像是
.item-parent{
column-count: 2;
column-gap: 20px;
-moz-column-count: 2;
-webkit-column-count: 2;
/*...*/
}
http://www.quirksmode.org/css/multicolumn.html
http://caniuse.com/#feat=multicolumn
或者,要支持 IE9,您可以手动包装两列并适当地设置样式。如果你不想深入研究生成器——模板系统应该已经解决了这个问题——你可以使用 Javascript:
$('.item-parent').each(function(){
$items = $('.item', this);
$items.slice(0, ($items.length+1)/2) //split in half, round up
.wrapAll('<div class="item-column">');
$items.slice(($items.length+1)/2)
.wrapAll('<div class="item-column">');
)};