多年来我一直有一个问题。
使用line-height: 1
的文本将会很紧凑,且会到达周围元素的顶部和底部。
使用其他行高的文本会更易读,但同时,它将不再到达周围元素的顶部和底部。
这里有一个问题的代码示例和一个hackish的解决方案。改变行高或字体大小都会破坏它。
这个问题是否有一个可靠的解决方案?
.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>
这里的行高被极端地设置,只是为了展示效果。
text-edge: text
将来会支持更好的解决方案,但目前只有这个折中的解决方案可用。 - undefined