I have a responsive flexbox box with dynamically rendered cards (from 1-10 cards rendered each api call) in my application. It Almost does exactly what i want it to do except the way it wraps.
Let's say i rendered 10 cards, if i resize screen so it turns into e.g. 4-4-2 the last 2 cards are centered, i want it to wrap so the last 2 cards start from the left and with equal spacing like the cards above. How can you do that?
EDIT to eloborate further: let's say i resize even further into 1-1-1-1-1-1-1-1-1-1 , the cards should appear centered, i still need the centering, but i want the last 2 cards to wrap from the left side if it turns into 4-4-2 or 3-3-2 etc.
https://codepen.io/hyrosian/pen/EXKZJz
.card {
text-align: center;
box-shadow: 0 1px 3px 0 #d4d4d5, 0 0 0 1px #d4d4d5;
max-width: 300px;
margin: 2rem;
padding-bottom: 1rem;
}
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.recipe-grid {
display: flex;
flex-wrap: wrap;
justify-content: space-around
}
<div class="container">
<div class="recipe-grid">
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
<div class="card">
<img src="https://www.edamam.com/web-img/40b/40bfe88c879112dfc1786938c6c36832.jpg">
<h3> Egg beef sandwich </h3>
<p> 604 kcal - totally vegan </p>
</div>
</div>
</div>