I have a problem that I've had for years.
A text with line-height: 1
will be compact and will reach the top and bottom of the surrounding elements.
A text with another line-height will be more readable but at the same time, it will no longer reach the top and bottom of the surrounding elements.
Here is a code example of the problem and a hackish solution. Changing the line-height or the font size will break it.
Is the a solid fix for this?
.wrap {
display: flex;
}
.first {
background: red;
width: 1rem;
}
.second,
.second2{
line-height: 2;
}
.second2 {
margin-top: -9px;
margin-bottom: -7px;
}
<strong>Problem:</strong> The letter "A" does not align with the red top.<br><br>
<div class="wrap">
<div class="first"></div>
<div class="second">A text that<br>spans on multiple rows</div>
</div>
<br><br>
<strong>Hackish fix:</strong> The letter "A" does align with the red top.<br><br>
<div class="wrap">
<div class="first"></div>
<div class="second2">A text that<br>spans on multiple rows</div>
</div>
The line-height is taken to the extreme, just to show the effect.