Do it with CSS only ,
the parameter will use column-count
and max-height
in the container.
see DEMO
but I'm not sure about sopport support.
This is similar to what you want, at least to some extent, but you will probably be better off with something in javascript.
EDIT: here I insert CSS:
.container { column-count: 3; -webkit-column-count: 3; -moz-column-count: 3; -ms-column-count: 3; -o-column-count: 3; vertical-align:text-top; max-height:100px; }
source share