Having looked at all options, I ended up implementing the layout similar to Pinterest in this way:
All DIVs are:
This makes them position in rows better than when they are floated.
- DIVs are not very different in height.
- You don't mind some minor violations of ordering (some elements that were below can be pulled up above).
- You don't mind the bottom line being of different height.