I have a group of elements, each with a different amount of content. I want to use display: flex
and justify-content: space-around
on their container to maintain an even amount of space between the elements and still have them fill the browser window horizontally.
The element widths are fixed, but not the height. The number of elements on a row and the amount of space between them should change depending on how much horizontal space the browser window has.
e.g.
| _____ _____ _____ |
| | | | | | | |
| | 1 | | 2 | | 3 | |
| |_____| |_____| |_____| |
| _____ _____ _____ |
| | | | | | | |
| | 4 | | 5 | | 6 | |
| |_____| |_____| |_____| |
| _____ _____ |
| | | | | |
| | 7 | | 8 | |
| |_____| |_____| |
| |
Floats don't work because items from the next row will float up next to taller elements from the previous row.
This is basically what I've tried, although I now realize that align-content
works on the cross axis and isn't what I'm looking for:
div.flexy {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-content: flex-start;
}
div.block {
flex-basis: 20rem;
}
Is there any way to do this?