砌体网格显示不正常

在这里,我试图让砌体网格到我的引导行值。 但是当我启动砌体网格时,我得到的网格在下面的行中的项目之间有很多空间。 我怎么解决这个?

完整的HTML:

     .grid-item {width:400px;}    



Campingaz Expert Plus Gas Barbecue

₹7995/-

17800

0 of 4 owners reached Add to cart



Milagrow Swimming Pool Robot : RoboPhelps

₹29709/-

150000

0 of 8 owners reached Add to cart



Stanley Socket Set

₹0/-

3

0 of 4 owners reached Add to cart



Yamaha 01V96i Digital Mixer

₹88630/-

227900

0 of 4 owners reached Add to cart



Campingaz Expert Plus Gas Barbecue

₹7995/-

17800

0 of 4 owners reached Add to cart



Milagrow Swimming Pool Robot : RoboPhelps

₹29709/-

150000

0 of 8 owners reached Add to cart



Stanley Socket Set

₹0/-

3

0 of 4 owners reached Add to cart



Yamaha 01V96i Digital Mixer

₹88630/-

227900

0 of 4 owners reached Add to cart
$(document).ready(function(){ $('.grid').masonry({ itemSelector: '.grid-item', columnWidth: 400 }); });

这是我现在得到的输出: 在此处输入图像描述

试试这个https://jsfiddle.net/2Lzo9vfc/132/

JS

 $(document).ready(function(){ $('.grid').masonry({ itemSelector: '.item', }); }); 

编辑使用最新版本的JQuery

砌体没有初始化。 另外, itemSelector不能是.grid-item ,而只能是.item 。 修复如下:

 $(document).ready(function(){ var container = document.querySelector('.grid'); var msnry = new Masonry( container, { // options columnWidth: 400, itemSelector: '.item' }); }); 

这是JSFiddle 。 我希望它有所帮助。