Trying to explain this might be a bit challenging, but I have prepared a demonstration on JSFiddle here.
Styling with CSS:
.container {
column-width: 100px;
column-gap: 5px;
border: 1px solid red;
margin: 5px auto;
}
#card {
padding: 10px 5px;
border: 1px solid black;
display: inline-block;
vertical-align: top;
column-break-inside: avoid;
background: white;
margin: 0 2px 15px;
}
Structure in HTML:
<div class="container">
<div id="card">
<img src="http://ecx.images-amazon.com/images/I/519zImiZraL._SL500_AC_SS100_.jpg">
</div>
<div id="card">
<img src="http://saigonexpres.com/wp-content/uploads/2016/06/Nokia-Asha-303-newshitechdigital-e1466994250562-100x75.png">
</div>
(more image cards...)
</div>
The key here lies in setting the column width and gap, along with adjusting the top margin of the cards appropriately. Experimenting with these settings can yield different outcomes. Best of luck!