关于em的CSS问题?
我正在尝试将网站的所有边距值转换为 em 来代替像素,但我很难弄清楚“em”实际上是什么。我认为这是基于用户浏览器设置(默认字体大小)的设定距离,但例如,当应用于 h1 或 ul 时,标准 1em 是不同的。有什么帮助吗?
I'm trying to convert all of my site's margin values to em in place of pixels, but I'm having a hard time trying to figure out what 'em' actually is. I thought it was a set distance based on the users browser settings (default font-size), but a standard 1em is different when applied to h1 or ul for example. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
em
基于字体大小(大写字母M
的宽度高度),因此它是一个相对测量值,基于任何字体大小适用于元素。查看jsfiddle 上的此标记的结果:
An
em
is based on the font size (thewidthheight of a capitalM
), so it is a relative measurement, based on whatever font size applies to the element.See the results of this markup on jsfiddle:
“1em 等于当前字体大小。2em 表示当前字体大小的 2 倍。例如,如果一个元素以 12 pt 的字体显示,那么 '2em' 就是 24 pt。'em' 是一个非常CSS 中有用的单元,因为它可以自动适应读者使用的字体”
http://www .w3schools.com/css/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"
http://www.w3schools.com/css/css_units.asp
这里有 Stackoverflow 相关的 EPIC 答案:
使用“em”调整字体大小仍然相关吗?
em
测量类型将取决于具体情况(元素父元素、元素类型/元素 css 属性),请在此处阅读完整且全面的解释:http://jontangerine.com/log/ 2007/09/the-incredible-em-and-elastic-layouts-with-css
Stackoverflow relevant EPIC answer here:
Is sizing fonts using "em" still relevant?
The
em
measure type will depend on the circumstances (the element parent, the element type / element css properties), read a complete and comprehensive explanation on this here:http://jontangerine.com/log/2007/09/the-incredible-em-and-elastic-layouts-with-css