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

前端 未结 9 1775
不思量自难忘°
不思量自难忘° 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 20:04

    The whole "62.5%=10px" thing is fundamentally broken anyway - 62.5% may or may not be 10px depending on the browser, the user's settings, and, especially, the minimum font size setting. So you can't just design in pixels and then "convert" to ems on the assumption that 62.5%=10px, because your design will break all the time. If you want a pixel-perfect design, you have to use pixels as the unit. If you want a flexible design, you need to think about the appropriate units for different elements of the web site - ems for elements which should scale relevant to text size, percentages for elements that should scale relative to window size, and pixels for elements (like images) that shouldn't scale at all.

    Anyone who includes font-size: 62.5% in their CSS fundamentally doesn't understand how to design for the web.

提交回复
热议问题