Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can flexbox divide items evenly on multiple rows?

Tags:

css

flexbox

I've played around with responsive flexbox grids, with no media queries.

http://jsbin.com/qurumisu/1 (rescale the window to see how it works)

It fits as many flex items as it can per row and stretches their width equally to fill the whole line. However, this doesn't help "orphan" items. If the first line fits 5/6 items there is only one left for the second line, making it stretch much wider than it's siblings. I would prefer to avoid this behavior by having the elements divided evenly on the amount of rows required.

Is this possible?

like image 591
Albin Avatar asked Feb 28 '14 03:02

Albin


People also ask

How do you get 3 items per row on flexbox?

For 3 items per row, add on the flex items: flex-basis: 33.333333% You can also use the flex 's shorthand like the following: flex: 0 0 33.333333% => which also means flex-basis: 33.333333% .

Which flex property will you use to flex items on multiple lines?

The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines.

How do you split a row in Flex?

And then to have equally sized columns you will have to set the flex-grow property of every child to "1", or you can also use the shorthand "flex:1". The text-align property is what I'm using here to center your text and your images inside each column.


1 Answers

No, not without media queries adjusting the flex-basis value. Flex items that stretch and wrap attempt to maximize the amount of items that fit on each row.

You may want to consider using the multi-column module instead, which will attempt to equally distribute elements across all of the columns created:

.foo {     columns: 100px; } 

http://caniuse.com/#feat=multicolumn

like image 173
cimmanon Avatar answered Sep 20 '22 16:09

cimmanon