Is there a way to create a layout without blank spaces where most items are the same dimensions, but some are 2x the height? I can make something similar to what I want with the following CSS:
Parent:
display: flex;
flex-direction: column;
justify-content: flex-start;
align-content: flex-start;
flex-wrap: wrap;
Children:
width: 22%
height: 100px;
The tall one has height: 200px
. It looks like this:
It's pretty close, but the problem is that I need a left-to-right order, not top-to-bottom, so I can't use flex-direction: column
. If I do the same with flex-direction: row
, it doesn't work:
Any ideas?
Depending on your overall scenario, you may be able to use the order
property.
The CSS
order
property specifies the order used to lay out flex items in their flex container.
Here's a basic flexbox with 20 flex items in column
alignment.
Numbering is vertical, like in your first image.
With order
you can rearrange the layout without changing the HTML or flex-direction
.
Items are stacked in columns, but the order
property overrides their natural positioning and rearranges them into rows, like in your second image.
Then, if you double the size of a few items, you just need to figure out the math for proper ordering (since each item will now occupy two spaces).
Note there is no extra vertical spacing between items.
All flex items are set to order: 0
by default. Negative values are permitted (i.e. order: -3
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With