TaylorMac TaylorMac - 2 months ago 12
CSS Question

CSS Keep all flexbox children elements the same size

My sass (using compass to get the prefixes) is shown in this fiddle
:

.container
@include display-flex
@include flex-wrap(wrap)
.item
@include flex-grow(1)
@include flex-basis(190px)


flexbox grid

Although, I would like the two items across the bottom to have the same with as the items on the top.

I don't want to float them left and fix their width, this will not work for my arrangement in other resolutions.

Any suggestions welcome!

Answer

You have 2 ways of doing this:

flex-grow: 0 (fiddle)

If you set flex-grow to 0 you are telling the items to keep their width and expand the empty space. Using flex-grow: 1 the items will expand the width to fit the space.

invisible items (fiddle)

Add some invisible items after the normal items with the same flex properties. You will get a left aligned look.

In this solution there will be the same number of items in all visible rows so make sure to add enough invisible items to work properly on larger screens.