I am creating a card which has a title and then below that it has other cards in columns of 2. The problem is that I want padding between the elements but not around them, at least not on the sides, since that makes the title misalign with the boxes below. Here is what I want:
I have tried to give each green card a different padding, so the top left have a padding of 0 1em 1em 0, the top right have 0 0 1em 1em and so on. It would be cleaner though if I could have a generic solution with any given number of cards, columns, rows and not "hard code" the padding like that. Is this possible?
One solution is to pad the title but that feels like an ugly solution.
Top and bottom padding can be present if that makes it easier, I just can't have it on the left or right.
The relevant code:
.content-card {
width: 100%;
padding: 2em 2em 2em;
background: black;
}
.service-card {
max-width: 100%;
padding: 1em 1em 1em;
background: grey;
border-radius: 0.25em;
}
.row {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.column-2x2 {
display: flex;
flex-direction: column;
flex-basis: 45%;
padding: 1em 1em 1em;
}
<div class="content-card">
<h2 style="color:white; font-size: 36px">Services.</h2>
<br>
<div class='row'>
<div class='column-2x2'>
<div class="service-card">
<h3 class="">Service 1.</h3>
</div>
</div>
<div class='column-2x2'>
<div class="service-card">
<h3 class="">Service 2.</h3>
</div>
</div>
<div class='column-2x2'>
<div class="service-card">
<h3 class="">Service 3.</h3>
</div>
</div>
<div class='column-2x2'>
<div class="service-card">
<h3 class="">Service 4.</h3>
</div>
</div>
</div>
</div>