I want to layout variable-height but fixed-width divs inside a fixed-width and variable-height container, so that the child divs look stacked on one another in a masonry kind of pattern, taking 2 or more columns.
Here's what I want:
And here's what I get with floats or FlexBox:
Here's the code pen: http://codepen.io/anon/pen/xOLwVJ
<div class="container">
<div class="item">
</div>
<div class="item" style="height:250px;">
</div>
<div class="item" style="height:150px;">
</div>
<div class="item" style="height:200px;">
</div>
<div class="item" style="height:180px;">
</div>
</div>
This code is only in reference to CodePen, not meant to represent the 2 images here.
Neither Flexbox nor Floats seem to work. The closest I have come to making it work is using columns, however they cut of child divs in the middle - it's ok for text, but not so for actual boxes.
I want HTML/CSS only solution with no JavaScript.