I am trying to center flex items within a flexbox with wrap so that the rows with most items are centered, but the other rows with less items also start at the same length.
This is the idea: Idea
The problem is that if justify-content: center;
makes the row with less items start at a different length.
Problem
the code:
.container {
display: flex;
flex-wrap: wrap;
background: orange;
gap: 0.5rem;
padding: 1rem;
}
.container > div {
height: 150px;
width: 150px;
background: purple;
}
<div class="container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
I tried wrapping the container inside another div with display: flex;
and justify-content: center;
but the container took up all the space in the parent div.