I have a page with lots of grid elements currently. The grid is in 3 columns and 2 rows for the most part.
Most of the sections of my grid only have 5 items, so 3 on the top row 2 on the bottom.
Is it possible to have the 2 bottom items centered instead of left aligned?
Curently:
▢ ▢ ▢
▢ ▢
Desired:
▢ ▢ ▢
▢ ▢
Below is a simplified version of my code that behaves as described above. Can I achieve what I wan't with display: grid;
or would I be better off using display: flex;
and if I have to go the flex route, I would prefer all the cards to be the same size (which is why I went for grid at the start)
.service-option-container {
margin: 1em 0 4em 0;
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 1em;
row-gap: 1em;
justify-content: center;
.service-option-card {
border: 1px solid black;
border-radius: 20px;
padding: 1em;
margin-left: 1em;
margin-right: 1em;
.extra-pad-bottom {
padding-bottom: 2em;
}
}
}
<div class="service-option-container">
<div class="service-option-card">Card Contents</div>
<div class="service-option-card">Card Contents</div>
<div class="service-option-card">Card Contents</div>
<div class="service-option-card">Card Contents</div>
<div class="service-option-card">Card Contents</div>
</div>
Also there are a few sections that have only 1 item in them and I would also like those to be centered.