How do I achieve this effect?
You can try Views Fluid Grid module 

This module provides the Fluid Grid style plugin for Views. This plugin displays the view as a fluid grid using an HTML list element.


  The plugin settings form provides options to define the width and
  height of the elements in the grid. But it also provides advanced
  layout options implemented in separate CSS classes that allow you to
  define item margins, alignment and a couple of CSS3 properties
  (box-shadow and border-radius).