【问题标题】:@font-face problems between strong tag and faux bold rendering强标签和仿粗体渲染之间的@font-face 问题
【发布时间】:2014-10-20 21:17:07
【问题描述】:

我的网站是通过@font-face 在 Avenir Medium 中设置的,如下所示:

@font-face {
    font-family: "Avenir-Medium";
    src: url("/Shared/fonts/Avenir-Medium.ttf") format('truetype'), 
    url("/Shared/fonts/Avenir-Medium.woff") format('woff');
}

我通过身体应用这个:

body {
    font-size: 1em;
    line-height: 1.25em; 
    background-color: #E8E8E8;
    font-family: "Avenir-Medium", Arial, Verdana, sans-serif;
}

这很好地为正文拉入了正确的字体。然而,<strong> 标签在 PC(Chrome、FireFox、IE 等)上看起来很糟糕,因为它是虚假的粗体渲染。在这一点上,我决定我需要引入 Avenir 的斜体/粗体版本:

@font-face {
    font-family: "Avenir-Heavy";
    src: url("/Shared/fonts/Avenir-Heavy.ttf") format('truetype'), 
    url("/Shared/fonts/Avenir-Heavy.woff") format('woff');
}

@font-face {
   font-family: "Avenir-MediumOblique";
   src: url("/Shared/fonts/Avenir-MediumOblique.ttf") format('truetype'), 
   url("/Shared/fonts/Avenir-MediumOblique.woff") format('woff');
}

在这些正确拉入之后,我制定了以下 CSS 规则:

strong {
    font-weight: normal;
    font-style: normal;
    font-family: "Avenir-Heavy", Arial, Verdana, sans-serif;
}


em { 
    font-weight: normal;
    font-style: normal;
    font-family: "Avenir-MediumOblique", Arial, Verdana, sans-serif;
}

这就是我的问题所在。在 Mac 上,会为任何 <strong> 和 <em> 声明引入正确的字体。不过,在 PC 上……人造渲染似乎正在抬起它丑陋的脑袋。粗体字体现在看起来很糟糕,即使浏览器说它正在为<strong> 声明引入 Avenir-Heavy。

您可以查看此问题的示例here。

【问题讨论】:

  • 尝试将字体上的font-weight:700更改为粗体版
  • 这些字体文件从何而来?
  • @JukkaK.Korpela 我们将它们托管在我们的服务器上。理想情况下,我想要像 google/typekit 这样的 CDN 上的东西,但现在不能使用这种字体。 ://
  • @Danko 一定会在我回到办公室时尝试一下。我对 font-weight: 700 或 800 运气不佳。会试一试,让你知道。
  • 您需要识别您正在使用的字体,以允许其他人测试它的方式,显示实际演示问题的最小文档,并清楚说明问题所在是直接可观察的。 “虚假渲染”是从某事中得出的结论,而不是观察。 如果 font-weight: normal 应用于元素,很难理解为什么会使用假粗体。

标签: html css fonts font-face


【解决方案1】:

当我遇到关于使用 google 字体“Alegreya SC”粗体、正常和斜体的类似问题时,我发现此链接非常有用。

http://www.paulirish.com/2009/bulletproof-font-face-implementation-syntax/

根据该网站,我使用 font squirrel 创建了更多字体格式,并提出了一个像这样的防弹版本

 @font-face {
            font-family:alegreyareg;
            src: url(webfontkit/alegreyasc-regular-webfont.eot?#iefix) format('embedded-opentype'),
                 url(webfontkit/alegreyasc-regular-webfont.woff) format('woff'),
                 url(webfontkit/alegreyasc-regular-webfont.ttf) format('truetype'),
                 url(webfontkit/alegreyasc-regular-webfont.svg#svgFontName) format('svg');
        }
        @font-face {
            font-family:alegreyabold;
            src: url(webfontkit/alegreyasc-bold-webfont.eot?#iefix) format('embedded-opentype'),
                 url(webfontkit/alegreyasc-bold-webfont.woff) format('woff'),
                 url(webfontkit/alegreyasc-bold-webfont.ttf) format('truetype'),
                 url(webfontkit/alegreyasc-bold-webfont.svg#svgFontName) format('svg');
        }
        @font-face {
            font-family:alegreyaital;
            src: url(webfontkit/alegreyasc-italic-webfont.eot?#iefix) format('embedded-opentype'),
                 url(webfontkit/alegreyasc-italic-webfont.woff) format('woff'),
                 url(webfontkit/alegreyasc-italic-webfont.ttf) format('truetype'),
                 url(webfontkit/alegreyasc-italic-webfont.svg#svgFontName) format('svg');
        }

这似乎对我有用。希望这对您也有帮助。

【讨论】:

  • 感谢您的回复。我今天完成了这个过程,但收到一条错误消息,指出 Linotype 铸造厂已要求字体松鼠不允许将 Avenir(以及他们提供的其他字体)转换为其他格式。不幸的是,它不是谷歌字体,我们托管的是 ttf 和 woff 文件。不过再次感谢。
  • 如果可能,请尝试搜索类似于 Avenir 的 google 或开源字体。我也有这个问题哈哈。我的客户想要一种 Adob​​e 专有的字体,因此我研究了字体世界并提出了非常接近原始字体的 Alegreya。谢天谢地,客户对替换没有意见。
猜你喜欢
  • 2011-09-14
  • 1970-01-01
  • 2012-03-05
  • 2012-09-12
  • 2011-02-02
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
  • 2013-10-23
相关资源
最近更新 更多