我正在更新一个网站,其中有很多部分的CSS属性font-size:larger
。什么是font-size:较大的字体是1em?
我想替换这个,以便它使用EMs,因为它更明确的尺寸是什么。
如果将font-size:larger
应用于1em字体,那么新字体有多少个EM?像1.2em的东西?
我正在更新一个网站,其中有很多部分的CSS属性font-size:larger
。什么是font-size:较大的字体是1em?
我想替换这个,以便它使用EMs,因为它更明确的尺寸是什么。
如果将font-size:larger
应用于1em字体,那么新字体有多少个EM?像1.2em的东西?
正如W3C CSS2 Fonts文件中提到:
<relative-size>
A <relative-size> keyword is interpreted relative to the table of font sizes
and the font size of the parent element. Possible values are: [ larger | smaller ].
For example, if the parent element has a font size of 'medium', a value of 'larger'
will make the font size of the current element be 'large'. If the parent element's
size is not close to a table entry, the UA is free to interpolate between table
entries or round off to the closest one. The UA may have to extrapolate table values
if the numerical value goes beyond the keywords.
低于这个,说:
Note 2. In CSS1, the suggested scaling factor between adjacent indexes was 1.5, which
user experience proved to be too large. In CSS2, the suggested scaling factor for a
computer screen between adjacent indexes was 1.2, which still created issues for the
small sizes. Implementation experience has demonstrated that a fixed ratio between
adjacent absolute-size keywords is problematic, and this specification does not
recommend such a fixed ratio.
我希望这回答了你的问题。
根据SitePoint Reference,你的猜测是完全正确的。大多数浏览器会将字体大小增加1.2em
,但他们没有这样做的标准。
W3C的建议是,您使用em
或%进行尺寸调整,因为页面上的元素大小将相互关联,而不依赖于某些不常用的浏览器中可能不使用的任意约定。
font-size:larger
将导致所选元素的字体大小大于其父容器中的字体大小。 CSS的标准字体大小是中等的。实际的px
或em
值取决于客户端/浏览器。通常它是1em,常见的转换是1em = 16px。