I want to create a grid of equal squares. I've been looking at CSS Grid as I thought it was possible to create equal width and height areas in grids. But I don't see anything in the Grid spec about it. The basic code is like this:
.squaregrid {
max-width: 600px;
margin: 20px;
display: grid;
grid-template: repeat(3, 1fr) / repeat(3, 1fr);
grid-gap: 10px;
}
.cell {
background: #ddd;
font-size: 2em;
}
<div class="squaregrid">
<div class="cell">A</div>
<div class="cell">B</div>
<div class="cell">C</div>
<div class="cell">D</div>
<div class="cell">E</div>
<div class="cell">F</div>
<div class="cell">G</div>
<div class="cell">H</div>
<div class="cell">I</div>
</div>
I get a 3x3 grid but the height of each "cell" is just the size of the letters (because the fr
unit makes the rows' height relative to each other, not relative to the column width).
I can use a fixed size instead of 1fr
but then of course it's not responsive.
I'm aware of the padding-bottom
trick which is used to maintain an aspect ratio, but that involves multiple wrappers for every cell, plus if I'm doing that there's not really any need to use Grid, I can use regular divs or flexbox.
Any other solutions out there?
Answers on the "duplicate" question do not solve the problem.