When using space-around
as a param to justify-content
, it will space the items evenly within the container. What I'd like is for all the items to start (flex-start
) on the left but have the same margin that space-around
would offer.
I think this shows the issue:
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
width: 100%;
border: 1px solid red;
}
.item {
flex: 0 0 16%; /*6 items per line leaving some for margin*/
border: 1px solid black;
box-sizing: border-box;
}
<div class="container">
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
</div>
What I'd like is for the second line to wrap and take up the first 2 columns. I know I could specify a padding on the .item
class and set the flex prop to flex-start
but I can't always be 100% sure of the size the padding should be as it's scaling for multiple devices.
This can be demonstrated like so:
.container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
width: 100%;
border: 1px solid red;
}
.item {
flex: 0 0 16%; /*6 items per line leaving some for padding*/
border: 1px solid black;
box-sizing: border-box;
margin-right: 0.66%
}
<div class="container">
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
<div class="item">ITEM</div>
</div>
The overall spacing of the items between the red border isn't right and again, without knowing specific values, I don't know how I can set it to be so.