There are at least two methods for equal space between all items, including the first and last items. One method, however, doesn't yet have full browser support.
pseudo-elements
Note this section from Firefox documentation:
In-flow ::after
and ::before
pseudo-elements are now flex
items.
In fact, all major browsers consider pseudo-elements on a flex container to be flex items.
Knowing that, add ::before
and ::after
to your container.
With justify-content: space-between
and zero-width pseudo-elements, the visible flex items will appear evenly spaced.
flex-container {
display: flex;
justify-content: space-between;
}
flex-container::before {
content: "";
}
flex-container::after {
content: "";
}
/* non-essential decorative styles */
flex-container {
padding: 5px 0;
background-color: lightyellow;
border: 1px solid #aaa;
}
flex-item {
height: 50px;
width: 75px;
background-color: lightgreen;
}
<flex-container>
<flex-item></flex-item>
<flex-item></flex-item>
<flex-item></flex-item>
<flex-item></flex-item>
</flex-container>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…