My problem is that I want the flexbox with variable range width, and all works well, but not on the last row. I want the same dimension for all children even where the row is not full of children (the last row).
#products-list { position:relative; display: flex; flex-flow: row wrap; width:100%; } #products-list .product { min-width:150px; max-width:250px; margin:10px 10px 20px 10px; flex:1; }
I created a dynamic situation in jsFiddle
My flex divs can shrink until 150px and grow up to 250px, but all must be with the same size (and obviously I want a CSS solution, with JS I know the way).
Flex items are displayed in the same order as they appear in the source document by default. The order property can be used to change this ordering.
Justify ContentFlex Start positions element at the start of the page. Flex End sets the element to the end of the page. Space Around arranges the items evenly but with spaces between them. The spaces will be equal among all the elements inside a flex-box container, but not outside them.
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% .
Unfortunately, in the current iteration of flexbox (Level 1), there is no clean way to solve the last-row alignment problem. It's a common problem.
It would be useful to have a flex property along the lines of:
last-row
last-column
only-child-in-a-row
alone-in-a-column
This problem does appear to be a high priority for Flexbox Level 2:
Although this behavior is difficult to achieve in flexbox, it's simple and easy in CSS Grid Layout:
In case Grid is not an option, here's a list of similar questions containing various flexbox hacks:
As a quick and dirty solution one can use:
.my-flex-child:last-child/*.product:last-child*/ { flex-grow: 100;/*Or any number big enough*/ }
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