There was already a similar question about Row Masonry Layout, answered here: Horizontal "masonry" type layout with variable row heights
One of the commenters (SB3NDER) have offered an example of such layout, css-only, on codepen. It seems a simple and nice example with explanations and comments offering the way to build the functionality you need. You may want to check it out.