Masonry is a more flexible method.
Masonry
Cascading grid layout library
What is Masonry?
Masonry is a JavaScript grid layout library. It works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall. You?ve probably seen it in use all over the Internet.