@font-face:FF 中的粗体比 Chrome 中的粗体
我使用了这段代码:
@font-face {
font-family: 'DroidSansRegular';
src: url('droidsans-webfont.eot');
src: url('droidsans-webfont.eot?#iefix') format('embedded-opentype'),
url('droidsans-webfont.woff') format('woff'),
url('droidsans-webfont.ttf') format('truetype'),
url('droidsans-webfont.svg#DroidSansRegular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'DroidSansBold';
src: url('droidsans-bold-webfont.eot');
src: url('droidsans-bold-webfont.eot?#iefix') format('embedded-opentype'),
url('droidsans-bold-webfont.woff') format('woff'),
url('droidsans-bold-webfont.ttf') format('truetype'),
url('droidsans-bold-webfont.svg#DroidSansBold') format('svg');
font-weight: bold;
font-style: normal;
}
当我使用font-weight:bold;
时,Chrome中的粗体文本就可以了,但在Firefox中就太粗了。
怎么解决这个问题呢?
PS:我必须使用本地文件中的字体。
I used this code:
@font-face {
font-family: 'DroidSansRegular';
src: url('droidsans-webfont.eot');
src: url('droidsans-webfont.eot?#iefix') format('embedded-opentype'),
url('droidsans-webfont.woff') format('woff'),
url('droidsans-webfont.ttf') format('truetype'),
url('droidsans-webfont.svg#DroidSansRegular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'DroidSansBold';
src: url('droidsans-bold-webfont.eot');
src: url('droidsans-bold-webfont.eot?#iefix') format('embedded-opentype'),
url('droidsans-bold-webfont.woff') format('woff'),
url('droidsans-bold-webfont.ttf') format('truetype'),
url('droidsans-bold-webfont.svg#DroidSansBold') format('svg');
font-weight: bold;
font-style: normal;
}
and when I using font-weight: bold;
then bold text in Chrome is ok, but in Firefox is too much bolder.
How to solve this?
PS: I have to use the fonts from local files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
FireFox 今天在其错误论坛上发布了解决方案。它今天才最终确定,因此暂时不会使用,但我们都应该放入
body
标记来为所有浏览器重置此设置。最后!!伙计,这让我很开心!这应该会在下一个 FF 版本中出现。线程在这里
https://bugzilla.mozilla.org/show_bug.cgi?id=857142
FireFox posted a resolution to this today on their bug forum. It was just finalized today so won't be in use for a while, but we should all put
in our
body
tag to reset this for all browsers. FINALLY!! man, that made my day! This should come out in the next FF release.thread here
https://bugzilla.mozilla.org/show_bug.cgi?id=857142
这里的问题是 FF 获取字体并对其应用粗体字体粗细(所以基本上它使效果加倍)。 Chrome 似乎没有改变字体粗细,只是使用了正确的字体。我认为发生这种情况是因为您声明了两种不同的字体系列。对于这种情况,正确的 CSS 是:
请注意,我将字体系列更改为“DroidSans”,而不是“DroidSansRegular”和“DroidSansBold”。
The Problem here is that FF takes the font and applies the bold font-weight to it (So basically it doubles the effect). Chrome doesn't seem to change the font-weight and just uses the right font. I think this happens because you declare two different font-families. The right CSS for this case would be:
Notice that I changed the font-family to "DroidSans" not "DroidSansRegular" and "DroidSansBold".
问题是 Firefox 尝试向文本添加粗体效果,即使对于已经是粗体的自定义字体也是如此。我刚刚遇到了完全相同的情况,并通过在 @font-face 声明上设置
font-weight: normal;
来解决它。示例:
您还需要在任何原本具有
font-weight:bold;
的元素(例如 h1、h2 等)上使用font-weight:normal;
否则 Firefox 仍会为自定义字体添加粗体。The issue is that Firefox tries to add the bold affect to text even for custom fonts that are already bold. I've just had the exact same situation, and resolved it by setting
font-weight: normal;
on the @font-face declaration.Example:
You'll also need to use
font-weight:normal;
on any element (e.g. h1, h2, etc) that would otherwise havefont-weight:bold;
set otherwise Firefox will still add bold to the custom font.您已指定两个不同系列中的两个面孔。您在名为“DroidSansRegular”的系列中定义了常规外观,并在名为“DroidSansBold”的系列中定义了粗体外观。 CSS 的设计希望您将它们定义为一个系列的两个权重。如果你让两者都说
font-family: "DroidSans";
,那么你可以使用一个名为“DroidSans”的字体系列,当你要求粗体时,你会得到该系列的粗体。(哎呀。所选答案已经给出了正确的解决方案,但没有完全解释出什么问题。)
You have specified two faces in two different families. You have defined a regular face in a family called “DroidSansRegular” and you have defined a bold face in a family called “DroidSansBold”. The design of CSS expects you to define those as two weights of one family. If you make both say
font-family: "DroidSans";
, then you can use a font family called “DroidSans” and when you ask for bold, you get the bold face from that family.(Oops. The chosen answer already gave the correct solution but didn’t quite explain what was wrong.)
我的问题是“更粗体”的文本位于 h1 标签内。我刚刚将以下内容添加到我的 CSS 中,它解决了问题! :)
My problem was that the text that was "more bold" was within a h1 tag. I just added the following to my CSS and it fixed the problem! :)
我使用了Alex的解决方案:
这在Firefox v24中仍然不起作用...今天,2013年10月28日。粗体@font-face问题仍然存在。
经过一番搜索,我在这里找到了这个解决方案:
https://support.mozilla.org/hu/questions/801491
令人遗憾的是,您确实无法对 Firefox 中的粗体字体做任何操作...您确实无法选择在用户的计算机上关闭此功能。硬件加速确实很重要。我想你只需要忍受它。他们在过去的三四年里没有解决这个问题。他们将来可能不会解决这个问题。
但是,我注意到这个问题可能不会影响外部 javascript 字体(例如:Typekit、EdgeFonts)。
希望Chrome能够在越来越多的用户PC上找到自己的路...
更新:
只能关闭部分硬件加速。教程在这里: http:// /www.mydigitallife.info/fix-firefox-4-fade-blur-bold-bad-and-ugly-font-rendering/
还提到了另一种解决方案:关闭各向异性过滤火狐在你的显卡的设置页面(但这对我不起作用)。
I used Alex's solution:
Which is still not worked in Firefox v24... Today, on 2013. october 28. the bold @font-face problem is still exist.
After a little search, I found this solution here:
https://support.mozilla.org/hu/questions/801491
Which is sad that you really can't do anything about the bold fonts in Firefox... You really not have option to turn this off on user's machines. Hardware Acceleration is really important. I guess you just need to live with it. They didn't fixed this in the last 3-4 years. Probaby they won't fix this in the future.
However, I noticed that maybe this issue not affecting the externel javascript fonts (for example: Typekit, EdgeFonts).
Hope that Chrome will find its way on more and more user's PC...
UPDATE:
It's possible only to turn off parts of the hardware acceleration. Tutorial here: http://www.mydigitallife.info/fix-firefox-4-fade-blur-bold-bad-and-ugly-font-rendering/
Also mentioned an another solution: turn off anisotropic filtering for Firefox in your graphic card's settings page (but this is not works for me).
这对我有用!
this worked for me!
在研究了这个问题之后,我找到了一个有效的解决方案。我应用了一些 CSS 属性,他们解决了这个问题。这就是我所做的:
首先,我将正文的字体设置为“Libre Baskerville”并带有衬线后备,您可以根据需要设置字体。然后,我添加了字体平滑的属性。通过减少锯齿状边缘,可以使文本在屏幕上看起来更好。这是 CSS 代码:
我还需要确保 Firefox 中的字体粗细正常。为此,我使用了仅影响 Firefox 的特殊 CSS 规则。这是代码的一部分:
After looking into the problem, I found a solution that worked. I applied some CSS properties, and they fixed the issue. Here’s what I did:
First, I set the font for the body to 'Libre Baskerville' with a serif fallback, you can set the font according to your need. Then, I added properties for font smoothing. This makes the text look better on screens by reducing jagged edges. Here’s the CSS code:
I also needed to make sure the font weight was normal in Firefox. To do that, I used a special CSS rule that only affects Firefox. Here’s that part of the code:
通常,基于 JavaScript 的字体渲染得更好,尽管由于渲染引擎的原因,所有内容在不同的浏览器中看起来都会有所不同。您甚至会注意到 Windows 和 Windows 之间的差异。 Mac 与相同的浏览器。
Typekit 往往是我最喜欢的选择。谷歌字体也做得很好。我认为 DroidSans 是 Google 或 Typekit 的一个选择。
Typically JavaScript based fonts render better, although everything is going to look different in different browsers because of the rendering engines. You'll even notice a difference between Windows & Mac with the same browser.
Typekit tends to be my favorite choice. Google fonts do pretty well also. I think DroidSans is an option at Google or Typekit.
简而言之,由于每个浏览器使用的渲染引擎和内部设置略有不同,确实没有办法解决这个问题。 (正如@LainBallard 提到的)。
如果您确实需要像素完美,那么您唯一真正的希望是使用图像,但我会尝试调整您的设计,以便您不需要像素完全匹配。
In a nutshell, there really isn't a way to solve this due to the slight differences in rendering engines and internal settings used by each browser. (as @LainBallard alluded to).
If you really need to have pixel-perfection, your only real hope is to use images, but I would try to tweak your design so that you don't need the pixels to match exactly.