I would like to lay out some elements in CSS which "flow" vertically in three or four columns, which would look like this :
The layout should put elements in the columns as evenly as possible.
A normal grid layout wouldn't work because of the vertical grid lines, and flexbox doesn't seem to offer anything with its column flow direction.
Does anyone have an idea for a good approach to laying out elements like this?

The answer depends on the sequence you want the elements to be displayed.
If you’re happy for the sequence to be column 1 top to bottom, followed by column 2 top to bottom, followed by column 3 top to bottom, then you can use CSS’s often-overlooked multi-column layout. Just style the wrapper with
columns: 3.If instead you want the first three elements to be displayed at the top of columns 1, 2 and 3, and then element 4 to be displayed in whichever column is the shortest, then that’s a masonry layout. Direct support for this in CSS is being worked on, but in the meantime there are various techniques you can try.