I would like to display a series of thumbnails in a gallery and would like them to be displayed evenly in their container while fitting exactly the width of that container.
I found a very good solution here (the one from Marcelo Amorim, not the popular one):
Distributing images evenly & horizontally in a Div via CSS
This is basically the solution he came up with:
#container {
text-align: justify;
}
.pic_bloc {
width: 130px;
height:160px;
display: inline-block;
vertical-align: top;
margin-bottom:30px;
}
.pic_bloc img{
width:130px;
height:160px;
}
#container:after {
content: "";
width: 100%;
display: inline-block;
}
This is my HTML:
<div id="container">
<div class="pic_bloc"><img src="1.jpg"/></div>
<div class="pic_bloc"><img src="2.jpg"/></div>
<div class="pic_bloc"><img src="3.jpg"/></div>
<div class="pic_bloc"><img src="4.jpg"/></div>
<div class="pic_bloc"><img src="5.jpg"/></div>
<div class="pic_bloc"><img src="6.jpg"/></div>
<div class="pic_bloc"><img src="7.jpg"/></div>
</div>
The problem is that it is too effective.
For instance, if I have two rows and 7 thumbnails, the first row will display evenly 5 thumbnails and the second row will display two thumbnails dispatched at the extreme positions, leaving the middle of that row completely empty.
Here is the result:
This is not what one intuitively expects from a standard gallery or list. So is there any way to get the same behavior but with the last row's thumbnails aligned to the left like this?
This would make a lot more sense for a gallery.
As the script uses a justified aligning, I suspect that it would require a complete different approach but I didn't find a clean solution by myself or online.
PS: jQuery or CSS, anything that works would do.
Thank you.