How is an em calculated?

后端 未结 3 991
独厮守ぢ
独厮守ぢ 2021-01-01 21:35

I have noticed that you can use 1em and it will look different on different sites.

What is an em in proportion to?

  • The font used?
  • The bigges
3条回答
  •  独厮守ぢ
    2021-01-01 22:18

    See http://w3schools.com/cssref/css_units.asp

    1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses

    An EM is relative to the current element it is defined on. If you use relative sizes (like 0.9em), they multiply and can lead to unexpected dimensions.

    Now, the default size of a font is not standard between browsers. And there's an issue with IE (at least older IE) when setting the font to a specific pixel unit. A good overview for font sizing can be found on A List Apart.

提交回复
热议问题