Not much to say, the code:
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.container:after {
content: "";
flex: auto;
}
In the code above, .container
it is the container element that contains the flex items. By justify-content
setting the property to space-between
, the items are justified on a single line. Enable items to wrap by setting the property flex-wrap
to .wrap
Then, :after
create a flex-item at the end of the container using a pseudo-element and set it to flex: auto
. In this way, when the item is less than one line, the flex item will occupy the remaining space, thereby aligning the item to the left.