我有一个砌体同位素网格,它有 n 行,两个列大小:160 像素 x 160 像素和 320 像素 x 320 像素,我想为每行的第一个和最后一个元素分配不同的样式。我的行可能有 4 个元素到 7 个元素。我一直在为此苦苦挣扎,想知道这是否可能。
HTML
<div id="grid" style="position: relative; overflow: hidden; height: 960px;"
class="isotope">
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="two_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="two_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="two_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_two">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
<div class="one_by_one">
<img class="thumb" src="https://s3.amazonaws.com/stitch-images/products/gucci.png"
/>
</div>
</div>
CSS
#grid {
margin:auto;
margin-top:55px;
margin-bottom:200px;
width:1140px
}
#grid .thumb {
width:97%;
height:97%
}
#grid .one_by_one {
width:160px;
height:160px;
background:url(https://s3.amazonaws.com/stitch-images/assets/cell_1x1.png);
cursor:pointer
}
#grid .one_by_two {
width:160px;
height:320px;
background:url(https://s3.amazonaws.com/stitch-images/assets/cell_1x2.png);
cursor:pointer
}
#grid .two_by_two {
width:320px;
height:320px;
background:url(https://s3.amazonaws.com/stitch-images/assets/cell_2x2.png);
cursor:pointer
}
JS
$("#grid").isotope masonry: layoutMode: 'fitRows'
查看我的 Jsfiddle http://jsfiddle.net/TDma4/