My code is shown in this JSFiddle:
#container { align-content: flex-start; background-color: red; display: flex; flex-flow: row wrap; height: 200px; justify-content: space-around; padding: 10px; width: 400px; } .child-item { background-color: yellow; flex-basis: 75px; flex-grow: 1; height: 20px; margin: 10px; width: 75px; }
<div id="container"> <div class="child-item"></div> <div class="child-item"></div> <div class="child-item"></div> <div class="child-item"></div> <div class="child-item"></div> <div class="child-item"></div> </div>
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.
you can try set flex-basis: 50%; and flex-grow: 1 . Show activity on this post. You can get the items to stop expanding with max-width on the elements (fiddle).
Getting the child of a flex-item to fill height 100%Set position: absolute; on the child. You can then set width/height as required (100% in my sample).
A flexbox item can be set to a fixed width by setting 3 CSS properties — flex-basis, flex-grow & flex-shrink. flex-basis : This property specifies the initial length of the flex item. flex-grow : This property specifies how much the flex item will grow relative to the rest of the flex items.
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.
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