Ems to Pixel Conversion - Why 62.5% and not 6.25%?

前端 未结 9 1779
不思量自难忘°
不思量自难忘° 2021-02-05 19:17

I know that a lot of us are familiar with setting the font size on the body element in our CSS to 62.5%. This means that 1em will equal 10px and helps for keeping things pixel p

9条回答
  •  [愿得一人]
    2021-02-05 19:50

    Arguably, but then you lose control over your scale. Don't forget that headings will typically inherit those same sizes in proportion to their rank (i.e.

    will be largest,

    slightly smaller). If you want to decrease those elements, you will need to use em values with a lot of decimal placeholders. Imagine

    font-size: 0.005em.

    Or worse, if you want fonts to be scaled larger, you could potentially be looking at font-size: 40em or something ridiculous.

    In short, 1em = 10px is much more practical for the scaled values of fonts. While a 1:1 scale might make sense on paper, it doesn't lend itself that well to sensible and maintainable CSS.

提交回复
热议问题