I'm a little new to CSS grid stuff, so forgive me if this is obvious, but I haven't found a good explanation for this so far.
In my mind, line-height:1 basically means "use the normal value." In fact, that code was buried deep in a CSS reset style I was using, so it was unclear why this problem was happening until I stripped it down.
Hopefully the example below is clear — I'm making a 3x3 grid, and I want the contents aligned to the far corners of each cell.
When line-height:1 is in effect, there is overflow on the top and bottom. When it is removed, it looks how I expect (no overflow).
(look for the text "THIS IS THE PROBLEM" in the CSS, below)
What's going on, here?
.outermost {
background-color:purple;
padding:10px;
}
.container { /* shard */
width:300px;
height:300px;
position:relative;
}
.container>div {
position:absolute;
width:100%;
height:100%;
left:0;
top:0;
}
.container {
background-color:lightblue;
}
.myGrid {
display:grid;
grid-template-columns: 33.3% 33.3% 33.3%;
grid-template-rows: 33.3% 33.3% 33.3%;
/* THIS IS THE PROBLEM */
/*
Why does setting line-height:1 cause
overflow on the top/bottom of the grid?
See: NW,N,NE, SW,S,SE
*/
line-height:1;
}
.myGrid span {
background-color:yellow;
}
.myGrid .gridNW {
align-self:start;
text-align:left;
}
.myGrid .gridN {
align-self:start;
text-align:center;
}
.myGrid .gridNE {
align-self:start;
text-align:right;
}
.myGrid .gridW {
align-self:center;
text-align:left;
}
.myGrid .gridC {
align-self:center;
text-align:center;
}
.myGrid .gridE {
align-self:center;
text-align:right;
}
.myGrid .gridSW {
align-self:end;
text-align:left;
}
.myGrid .gridS {
align-self:end;
text-align:center;
}
.myGrid .gridSE {
align-self:end;
text-align:right;
}
<div class="outermost">
<div class="container">
<div class="myGrid">
<div class="gridNW"><span>NW</span></div>
<div class="gridN"><span>N</span></div>
<div class="gridNE"><span>NE</span></div>
<div class="gridW"><span>W</span></div>
<div class="gridC"><span>C</span></div>
<div class="gridE"><span>E</span></div>
<div class="gridSW"><span>SW</span></div>
<div class="gridS"><span>S</span></div>
<div class="gridSE"><span>SE</span></div>
</div>
</div>
</div>
In case this is browser-dependent, I'm on Firefox and this is what it looks like for me:

line-height: normal;?