I have elements structured roughly like this: http://jsfiddle.net/zyySd/
Is there any way to achieve this: http://jsfiddle.net/zyySd/1/
without resorting to taking the elements out of the document’s flow and hardcoding absolute positioning values? In the case that I don’t know what the dimensions of the divs are, I would not be able to use absolute position as I did in the second JSFiddle.
CSS can’t really do it. You need JavaScript.
jQuery Masonry is good: http://masonry.desandro.com/
There’s also a no-framework version, Vanilla Masonry: http://vanilla-masonry.desandro.com/