It's strange that CSS grid doesn't have properties that can do this easily (my codepen here: https://codepen.io/Chiz/pen/dydeZpz).
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
grid-gap: 20px;
align-items: center;
justify-content: center;
}
.container div {
background-color: gray;
height: 100px;
}
<div class="container">
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
<div>Box 4</div>
</div>
If I use align-self: center
and justify-self: center
inside the .container div
part, it shrinks the sizes of the boxes down to the size of the content.
Shouldn't CSS grid have properties such as grid-item-align:top center sort of thing? I'm trying not to use 90s CSS hacks to do this cos' that would defeat the purpose of CSS grid.
With flexbox, it's far easier to align things where I want.