Vertically Flowing Masonry

How to create a grid for boxes/rectangles with same dynamic width but different fixed height to occupy the available container width.

CSS only, JS just to set random heights at first. Open it in a new tab and play resizing the result window.