这是一个类似问题的小提琴:http: //jsfiddle.net/DougCassidy/Gawe7/ 它工作得很好,但是,我想在盒子之间有一些很好的间距。如果右边距被视为盒子之间的最小间距会很好,这样如果间距低于该数量,它会将所有内容向下移动一行。此外,当前连续的最后一个框不应有右边距。
然后,一些底部边距。固定数量就可以了,或者等于当前水平间距的数量也可以。
$(new Array(9).join('<div class="invisible"></div>\n')).insertBefore('.stretch');
$(window).on('resize', function() {
$('#container').height($('.box').last().position().top + $('.box').last().outerHeight());
//make it still justify when there's only one row
if ($('.box').first().position().top == $('.box').last().position().top) {
$('.invisible').hide();
} else {
$('.invisible').show();
}
}).resize();