How do I dynamically increase rows and column based on screen size?

Hi all,

I would like to implement a image gallery whereby it will dynamically increase rows and columns based on the size of the phone. I was looking at collection-repeat link where it implements grid which is something that I am looking for. However, it only restrict the rows and columns to three. Any ideas or examples that I can take a look? Thanks.