What is the relationship between ems and pixels?

夙愿已清 提交于 2020-01-01 06:29:05

问题


What is the value of an em in terms of pixels?

10em = ?px ?


回答1:


There's no specific relationship between em and px. It's computed based on the width of the "m" character for each font-face.




回答2:


While as others have said, there is no set ratio - as it varies from font to font - it is possible to calculate this for a particular font face/size combination by using DHTML.

Simply create a div with

style="width: 1em; visibility:hidden"

and append it to the place in the document you are interested about.

You can then find out its width by checking the div's clientWidth property




回答3:


It depends on the font and the platform you're rendering on. There is no universal ratio.




回答4:


It's about 160px, if 1em is 16px and 10em = 1000%. It's just an approximation, which will depend on font, browser and OS.




回答5:


If you are using a standard sized text font of 11 or 12px then a general rule of thumb is 1em is going to be about that big in pixels, so 11 or 12 pixels.




回答6:


By default 1em is 16px (font-size:100%;), so 16px x 10em = 160px

You can change the size of an em by changing the percent of the font-size in the body, for example if you want to change the size of an em to 10px, this would be your CSS:

body {
font-size:62.5%;
}

16px x 62.5% = 10px



来源:https://stackoverflow.com/questions/1462997/what-is-the-relationship-between-ems-and-pixels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!