私はStackOverflowで非常に多くの答えを探しましたが、何も助けにはならないようです。私は以下のコードを持っています。それは、(現在のテストの画像の)初期化されていない石積みがうまく積み重なっているようですが、失敗します。理由私は石積みが必要です、画像が常に整列しないためです。石積みのギャラリーが正しく積み重なっていない
HTML
<div class='gallery'>
<!-- Grid sizing element 33.33% -->
<div class="grid-sizer"></div>
<!-- Two 50% -->
<div class='masonry-item gallery-item image-half'>
<a data-fluidbox="true" href="http://placehold.it/450x250"><img class="img-responsive" src="http://placehold.it/450x250" alt="450x250" /></a>
</div>
<div class='masonry-item gallery-item image-half'>
<a data-fluidbox="true" href="http://placehold.it/450x250"><img class="img-responsive" src="http://placehold.it/450x250" alt="450x250" /></a>
</div>
<!-- One 100% -->
<div class='masonry-item gallery-item image-full'>
<a data-fluidbox="true" href="http://placehold.it/900x400"><img class="img-responsive" src="http://placehold.it/900x400" alt="900x400" /></a>
</div>
<!-- Three 33.33% -->
<div class='masonry-item gallery-item image-third'>
<a data-fluidbox="true" href="http://placehold.it/300x500"><img class="img-responsive" src="http://placehold.it/300x500" alt="300x500" /></a>
</div>
<div class='masonry-item gallery-item image-third'>
<a data-fluidbox="true" href="http://placehold.it/300x500"><img class="img-responsive" src="http://placehold.it/300x500" alt="300x500" /></a>
</div>
<div class='masonry-item gallery-item image-third'>
<a data-fluidbox="true" href="http://placehold.it/300x500"><img class="img-responsive" src="http://placehold.it/300x500" alt="300x500" /></a>
</div>
</div>
CSS
.gallery .gallery-item {
margin-bottom: 20px;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 400px;
}
.grid-sizer { width: 33.33%; }
.gallery .gallery-item img{
max-width: 100%;
}
.gallery .image-full {
width: 100%;
background: red;
}
.gallery .image-half {
width: 50%;
background: blue;
}
.gallery .image-third {
width: 33.33%;
background: green;
}
.grid-item {
margin-bottom: 10px;
}
はJavaScript
var $gallery = $(".gallery");
$gallery.imagesLoaded(function() {
$gallery.masonry({
percentPosition: true,
columnWidth: '.grid-sizer',
itemSelector: '.gallery-item',
});
});
ん[これは](https://jsfiddle.net/xf07rf7s/)助け:
はあなたに
.grid-size
のための小さな乗数を使用する必要がありますか? –ありがとうございました。その場合はうまくいきましたが、それ以上のアイテムを追加すると再び壊れてしまいます –