space-between
does exactly what it says, it adds space between the elements.
If you want to reduce the space, you should also say how to reduce the space: e.g. increasing the size of boxes, increasing the space between the item and the border, and so on.
I provide you 3 solutions:
1. Using space-evenly
in place of space-between
. It will space the elements evenly considering also the container border as an element:
.box{
display: flex;
justify-content: space-evenly;
}
.item{
background-color: rgb(255, 157, 0);
width: 50px;
height: 50px;
}
<div class="box">
<div class="item"></div>
<div class="item"></div>
</div>
2. Adding margins to elements. In this way, you can decide how far you can get the element from the container border. In my example I use a value of 100px:
.box{
display: flex;
justify-content: space-between;
}
.item{
background-color: rgb(255, 157, 0);
width: 50px;
height: 50px;
margin: 0 100px;
}
<div class="box">
<div class="item"></div>
<div class="item"></div>
</div>
Note that I don't need to distinguish margin-left/margin-right because the unused margin gets just absorbed by flex.
3. Using flex-grow
, this will allow items to grow and use more space when available:
.box{
display: flex;
justify-content: space-between;
}
.item{
background-color: rgb(255, 157, 0);
width: 50px;
height: 50px;
flex-grow: 0.1;
}
<div class="box">
<div class="item"></div>
<div class="item"></div>
</div>
I hope that one or more of these solutions helped you