【发布时间】:2021-10-27 14:56:12
【问题描述】:
运行以下代码sn -p:
span.text {
border: 1px solid blue;
line-height: 1;
}
span.box {
display: inline-block;
border: 1px solid red;
height: 1em;
}
span.true-height {
display: inline-block;
height: 1.2em;
width: 1em;
background: green;
vertical-align: text-bottom;
}
<span class="text">This box is taller than 1em</span>
<span class="box">1em</span>
<span class="true-height"></span>
您会注意到两个跨度的高度不同。只包含文本(line-height: 1)的跨度大于 1em。
字体之间的“真实字体高度”和em的差异是否一致?在上面的例子中,“真实字体高度”是1.2em。这是一种产品字体文件格式,还是仅针对这种字体?
【问题讨论】:
-
line-height计算整个字体高度,height忽略字体的实际高度。通过同时选择.text和.box可以看到相同的结果。选择从.box中的框中溢出。