Hi there! This can sometimes be tricky to accomplish due to the way CSS and HTML works. The easiest way to do this would be to use a jQuery plugin called Masonry, which is often used to achieve these kinds of effects.
First of all, a quick suggestion: don’t edit the theme files directly, otherwise your changes will be overwritten whenever the theme is updated. For this change, you’ll want to make child theme. That way, you can change the theme’s functionality while still benefiting from its updates.
Once you have a child theme ready, you can implement Masonry for your theme by following this guide.
Cheers!