相同的字体除了粗细在不同浏览器上看起来不同
文本在 Chrome 中正确显示。我希望它在所有浏览器中都以这种方式显示。我该怎么做?
我可以在 Safari 中使用 -webkit-font-smoothing: antialiased;
Chrome 修复此问题:
火狐浏览器:
h1 {
font-family: Georgia;
font-weight: normal;
font-size: 16pt;
color: #444444;
-webkit-font-smoothing: antialiased;
}
<h1>Hi, my name</h1>
还有一个 JSFiddle: http://jsfiddle.net/jnxQ8/1/
The text is correctly displayed in Chrome. I want it to display this way in all browsers. How can I do this?
I was able to fix this in Safari with -webkit-font-smoothing: antialiased;
Chrome:
Firefox:
h1 {
font-family: Georgia;
font-weight: normal;
font-size: 16pt;
color: #444444;
-webkit-font-smoothing: antialiased;
}
<h1>Hi, my name</h1>
And a JSFiddle: http://jsfiddle.net/jnxQ8/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
确保所有浏览器的字体都相同。如果是相同的字体,那么使用跨浏览器CSS就无法解决该问题。
因为每个浏览器都有自己的字体渲染引擎,所以它们都是不同的。它们在更高版本中或在不同操作系统中也可能有所不同。
更新:对于那些不了解浏览器和操作系统字体渲染差异的人,阅读此内容和此内容。
然而,大多数人甚至都没有注意到这种差异,并且用户也接受了这一点。忘记像素完美的跨浏览器设计,除非您:
更新:我检查了示例页面。通过文本渲染调整字距调整应该有所帮助:
更多参考:
font-smoothing
(如上所述),另一部分是文本渲染
。调整这些属性可能会有所帮助,因为它们的默认值在不同浏览器中并不相同。Be sure the font is the same for all browsers. If it is the same font, then the problem has no solution using cross-browser CSS.
Because every browser has its own font rendering engine, they are all different. They can also differ in later versions, or across different OS's.
UPDATE: For those who do not understand the browser and OS font rendering differences, read this and this.
However, the difference is not even noticeable by most people, and users accept that. Forget pixel-perfect cross-browser design, unless you are:
UPDATE: I checked the example page. Tuning the kerning by text-rendering should help:
More references here:
font-smoothing
(as mentioned) and another part istext-rendering
. Tuning these properties may help as their default values are not the same across browsers.为了最好地标准化跨浏览器的 @font-face 嵌入字体,请尝试在 @font-face 声明或正文字体样式中包含以下内容:
目前,似乎没有跨所有平台和浏览器版本的通用修复程序。正如经常提到的,所有浏览器/操作系统都有不同的文本渲染引擎。
In order to best standardise your @font-face embedded fonts across browsers try including the below inside your @font-face declaration or on your body font styling:
At present there looks to be no universal fix across all platforms and browser builds. As stated frequently all browsers/OS have different text rendering engines.
这里有一些关于此的重要信息:
https://bugzilla.mozilla.org/show_bug.cgi?id=857142
仍在试验,但到目前为止仅针对 FF 的微创解决方案是:
There's some great information about this here:
https://bugzilla.mozilla.org/show_bug.cgi?id=857142
Still experimenting but so far a minimally invasive solution, aimed only at FF is:
尝试 -webkit-font-smoothing: subpixel-antialiased;
Try
-webkit-font-smoothing: subpixel-antialiased;
我收集并测试了讨论的解决方案:
Windows10 Prof x64:
macOs X Serra v.10.12.6 Mac mini(2010年中):
Semi(在Safari中仍然微胖)解决了胖字体:
没有视觉效果
错误的视觉效果:
不要忘记测试时设置 !important 或确保您的样式未被覆盖
I collected and tested discussed solutions:
Windows10 Prof x64:
macOs X Serra v.10.12.6 Mac mini (Mid 2010):
Semi (still micro fat in Safari) solved fatty fonts:
Have no visual effect
Wrong visual effect:
do not forget to set !important when testing or be sure that your style is not overridden
我有很多网站都有这个问题& 终于找到了解决方法,解决了 Firefox 字体比 Chrome 字体更粗的问题。
您需要在 -webkit 修复旁边添加此行
-moz-osx-font-smoothing: Grayscale;
I have many sites with this issue & finally found a fix to firefox fonts being thicker than chrome.
You need this line next to your -webkit fix
-moz-osx-font-smoothing: grayscale;
我认为在屏幕上使用“点”作为字体大小不是一个好主意。尝试在字体大小上使用 px 或 em。
来自W3C:
I don't think using "points" for font-size on a screen is a good idea. Try using px or em on font-size.
From W3C:
尝试文本渲染:geometricPrecision;。
与
text-rendering:optimizeLegibility;
不同的是,它在缩放字体时处理字距调整问题,而后者则启用字距调整和连字。Try
text-rendering: geometricPrecision;
.Different from
text-rendering: optimizeLegibility;
, it takes care of kerning problems when scaling fonts, while the last enables kerning and ligatures.