I have a boot grid with dynamically generated images.
If the last element is one in a row, it should be centered. And if there are two elements in a row, the second element should float to the right.
This is what I want:
Two items in a row:
A B D
E F G
H I
One item per line:
A B D
E F G
H
HTML code:
<div class="row">
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
<div class="col-md-4">
<img src="img.jpg" />
</div>
</div>
This is what I get:
Two items in a row:
A B D
E F G
H I
One item per line:
A B D
E F G
H
I tried it with :last-child:nth-child(odd)and :last-child:nth-child(even), but in the first line the first element is odd, in the second line the first element is even, in the third line the first element is odd again and so on.
Please note that the size of the content varies.
source
share