Live Demo
The demo employs the regular CSS property display: grid
for the wrapper element. For demonstration purposes, we limit the number of columns. Additionally, the solution incorporates vanilla JavaScript (without dependencies) that iterates through the grid elements. Each element can then be positioned vertically with the expected margin-block-start
, taking into account the previous element in the same column, its size, and, of course, the grid row gap for consistency.