I am looking for something like this……..

If it is only in the horizontal direction then float:left would do the trick…. but if we want an element to take up the vertical space whenever possible, then how do we do it? Be it an image or any DOM element, how do we get this type of alignment dynamically?
Please go through the Jquery Masonry plugin.
It is designed to address exactly this issue.
URL: http://masonry.desandro.com