我有一个砖石网格,有时最后一行少于4个项目。我希望最后一行在我的容器中间居中。最后一行中的项目数可能会有所不同,具体取决于我的页面响应能力,这就是为什么我无法使用CSS来识别最后一行项目。
如果有人有解决方案,请帮忙。 https://jsfiddle.net/oaoLuh4f/
$('.masonry').masonry({
itemSelector: '.masonry-brick',
isFitWidth: true,
animationOptions: {
duration: 400
}
});
$('.masonry').isotope({
itemSelector: '.masonry-brick',
layoutMode: 'fitRows',
});
$.each($(".masonry-brick"), function() {
var blockHeight = $(this).outerHeight();
$(this).css({
"height": blockHeight
});
});
$.each($('.masonry'), function() {
var masonryWrapperWidth = $(this).outerWidth();
$('.masonry').css({
"width": masonryWrapperWidth,
});
});

.masonry {
margin: auto;
}
.masonry-brick {
width: 150px;
margin: 5px;
color: #262524;
}

<script src="//cdnjs.cloudflare.com/ajax/libs/masonry/3.3.2/masonry.pkgd.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="masonry">
<div class="masonry-brick">
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x200" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x250" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x100" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x200" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x250" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="masonry-brick">
<img src="http://placehold.it/150x250" alt="" />
</div>
</div>
&#13;