font-size和line-height在浏览器内部渲染是有相应的规则吗?

<div style="line-height:200px; border:1px solid #34538b;">
    <span style="font-size:60px; border:1px solid #a0b3d6;">大大的文字</span>X后面是静止的文字。
</div>

clipboard.png

为什么div高度不为200,设置一段的font-size,比如53,54,55px,在chrome,opera中div高度不会改变,而firefox是0.25的往上递加,font-size和line-height在浏览器内部是有相应的规则吗?

阅读 2.8k
4 个回答

CSS2 没有具体定义字体高度怎么影响盒子高度,所以不同 UA 可能会有细微差异。

The height of the content area should be based on the font, but this specification does not specify how.

另外

Note: level 3 of CSS will probably include a property to select which measure of the font is used for the content height.

主要原因是line-height是一个可继承的属性,所以外面的div设置了行高之后,里面的span也继承了这个行高,导致div的高度被撑大了。将span的行高重新设置一下,比如60,就可以看到效果。

“字体”所在行这个东西的大小不止受font-size,line-height影响,还受字体本身影响。
具体的你可以看看这个,虽然我也看过- -,但是我已经忘了说了啥了。

推荐问题