那些在调整字体大小时使用 em 的人会知道,在处理嵌套元素时他们会很头疼,并且必须制作 px -> em 计算(以确保您的设计解释是正确的 @ 100%)会消耗额外的时间。
考虑到这些(诚然是次要的)问题,并考虑到主要浏览器最近在 native 处理页面缩放/缩放等可访问性问题方面取得的进展,仍在使用 em 来调整字体大小算值吗? *
*旧版浏览器 (IE6) 不支持。
最佳答案
不要以绝对长度单位为屏幕样式表指定字体大小。它们在不同平台上呈现不一致,并且不能由用户代理(例如浏览器)调整大小。在具有固定和已知物理属性(例如打印)的媒体上使用此类单元进行样式设计
如果你会用这个方法,不需要计算
您可以将正文的字体大小设置为 62.5%(即默认值 16px 的 62.5%),相当于 10px,即 0.625EMs。现在,您可以使用易于内存的转换方式在 EM 中设置字体大小,将 px 除以 10。
* 12px = 1.2EMs
* 13px = 1.3EMs
* 16px = 1.6EMs
* 8px = 0.8EMs
* etc…
这使得一切都非常容易记住,并且消除了对转换表的需要。当然,如果您在 CSS 中没有具体说明,那么在使用 EM 时您仍然需要为嵌套元素使用转换表,这是一个完全不同的问题。
但 76% 更好,您可以使用它来计算 http://pxtoem.com/
是的,它仍然相关:
IE6仍然广泛使用,无法调整px中定义的字体大小。 => 可用性问题。仅此一项是不行的。
和
实际上,IE 7 和 8 也不会调整以像素为单位的文本大小。他们确实有页面缩放功能,但有些人更喜欢只增加文本大小。
这里总结了一般字体大小的优缺点。
Font size in css http://easycaptures.com/fs/uploaded/213/2470522253.png
我个人喜欢ems。其他人,例如 CSS-Tricks.com 的 Chris Coyier,喜欢像素。 (Chris has an excellent article on the different font units)。
这真的取决于个人喜好。
关于SO的几乎相似或相关的问题
Should we still use em and % for defining the font-size of the website elements?
Is there really any point to using relative font sizing in CSS?
CSS font size: relative vs. absolute values. Which to use?
EM 问题
Using relative instead of fixed size in CSS
px 到 em 的有用在线工具
http://convert-to.com/pixels-px-to-em-conversion.html
将整个站点从 px 转换为 em(此工具仍在开发中)
http://converter.elementagency.com/
EM 计算器 AIR 应用程序(适用于所有操作系统)
http://jameswhittaker.com/journal/em-based-layouts-vertical-rhythm-calculator/
http://jameswhittaker.com/projects/apps/em-calculator-air-application/
Windows 应用
http://www.thebrightlines.com/2009/11/16/pixem-pixel-to-em-converter/
http://www.storkas.com/Projects.aspx(go在底部)
CSS 的像素到 Ems 转换表
http://jontangerine.com/silo/css/pixels-to-ems/
http://reeddesign.co.uk/test/points-pixels.html
emchart
http://aloestudios.com/tools/emchart/
http://aloestudios.com/code/emchart/
关于这个问题的更多文章
http://www.d.umn.edu/itss/support/Training/Online/webdesign/type.html
关于css - 使用 "em"调整字体大小是否仍然相关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2058550/