I have a flex-div with 7 elements in it.
<div class="d-flex flex-wrap justify-content-around">
<div style="width: 350px">
[...]
</div>
[6 more identical divs]
</div>
On large screens, there are 3 divs in each row, on medium screens 2 and on small screens only 1. The last element is always centered but I want it to be aligned right. I tried margin-left: auto on the last element but due to justify-content-around there should be space on the right (first 2 rows on large screens, first 3 rows on medium screens). Unfortunately, margin-left: auto pushes the last element all the way to the right without the space from justify-content-around. How can I position the last element exactly as if it was an element of the right column?
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
.ml-auto {
margin-left: auto
}
<h3>
Without margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card" style="width: 200px">
7 is centered
</div>
</div>
<h3>
With margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card ml-auto" style="width: 200px">
7 is too far to the right
</div>
</div>