【问题标题】:Google Font Weight 300 not working谷歌字体粗细 300 不起作用
【发布时间】:2016-11-03 21:04:30
【问题描述】:

无法在 Chrome 或 Chrome Canary 中使用 google fonts open sans 获得 300 的权重。

我已经在codepen 中尝试过this 和this,但无济于事。在边缘工作正常。

HTML

<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600" rel="stylesheet">
<div class="header-pic text-align-center">
  <h1>We make dream places <br> affordable for you.</h1>
</div>

CSS

body {
    font-family: 'Open Sans', sans-serif;
}
.header-pic h1{
    font-size: 80px;
    font-weight: 300;
}

有什么想法吗?

编辑: 澄清一下,不工作意味着没有显示 300 和 400 之间的差异。添加了屏幕截图。

添加了cmets截图和codepen,因为它显示的冷漠更清晰。

http://codepen.io/anon/pen/YWVLYE 这就是它应该是的样子: 这是它在我的 chrome 中的外观:

【问题讨论】:

  • 定义“不工作”。它看起来在你的例子中为我在 Chrome 中工作
  • 对我来说很好
  • 它在 Mozilla 和 chrome 上都可以正常工作
  • 我在本地运行时也遇到了这个问题。起初我以为这只是我的眼睛。这是 OP 的 Codepen 演示的修改版本,它们彼此相邻显示:codepen.io/anon/pen/YWVLYE。这是来自 Chrome 的屏幕截图:i.imgur.com/dpIDEM4.png
  • font-weight: 300; 正在您的 codepen 示例中工作

标签: html css fonts


【解决方案1】:

我认为你应该从头开始,转到 google fonts,搜索 opensans 字体,然后选择你想要的所有类型,然后下载 zip。 下载 zip 文件后,转到fontsquirrel,将此 zip 文件上传到字体生成器部分,然后您将获得字体解压缩并将它们添加到项目中的字体文件夹,然后您可以在 zip 文件中包含 styleshit.css 中给出的代码来自https://www.fontsquirrel.com/tools/webfont-generator,它看起来像这样。

@font-face {
    font-family: 'open_sansregular';
    src: url('../fonts/opensans-regular-webfont.eot');
    src: url('../fonts/opensans-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('../fonts/opensans-regular-webfont.woff2') format('woff2'),
         url('../fonts/opensans-regular-webfont.woff') format('woff'),
         url('../fonts/opensans-regular-webfont.ttf') format('truetype'),
         url('../fonts/opensans-regular-webfont.svg#open_sansregular') format('svg');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'open_sanssemibold';
    src: url('../fonts/opensans-semibold-webfont.eot');
    src: url('../fonts/opensans-semibold-webfont.eot?#iefix') format('embedded-opentype'),
         url('../fonts/opensans-semibold-webfont.woff2') format('woff2'),
         url('../fonts/opensans-semibold-webfont.woff') format('woff'),
         url('../fonts/opensans-semibold-webfont.ttf') format('truetype'),
         url('../fonts/opensans-semibold-webfont.svg#open_sanssemibold') format('svg');
    font-weight: normal;
    font-style: normal;
}

...等等您从谷歌字体中选择的所有字体类型。在添加字体系列时,只需添加 font-family:'open_sansregular';我发现这是避免所有开销和浏览器兼容性的最佳解决方案,谢谢。

提示:我多次发现如果您使用 cdn 直接链接到字体,那么它可能无法加载,而且某些浏览器将无法获取您键入的字体系列。所以在你的项目中包含字体总是有帮助的。

【讨论】:

  • 成功了!也许如果您可以更新您的答案,以反映您必须单独而不是按重量调用这些字体。
  • 很高兴!它帮助了你。
  • 但请注意,这是基于不再适用的 webfont 加载模式:eot 不再使用,除了 IE8 及以下版本,svg 是一种不再维护的格式,并且已被大多数主要浏览器主动删除,WOFF 是 ttf 和 otf 源的逐字节包装器,每个支持 ttf/otf 的浏览器也支持 WOFF(因此没有理由同时加载两者) .对于现代浏览器,加载 WOFF(如果需要,加载 WOFF2,但仍然不支持),如果您确实需要 IE8 支持,则添加 eot,这是您唯一需要的两个。
【解决方案2】:

尝试在正文中添加以下 css:

body{
    text-rendering: optimizeLegibility;
    text-rendering: geometricPrecision;
    font-smooth: always;

    font-smoothing: antialiased;
    -moz-font-smoothing: antialiased;
    -webkit-font-smoothing: antialiased;
    -webkit-font-smoothing: subpixel-antialiased;
   }

【讨论】:

  • 我看到第一段文字较浅,第二段文字比第一段略粗。
【解决方案3】:

这个例子对我来说很好。 300 使用的是 Open Sans Light,而 400 只是使用普通的“Open Sans”。

要检查这一点,我右键单击标题,检查元素和 chrome 开发工具的样式部分,单击计算,有一个部分显示它正在使用什么字体以及它使用的是本地文件还是网络文件。当我查看它时,它正在使用本地文件。

通过这种方式,您可以查看是 Google 字体未加载还是本地文件覆盖了网络文件。

抱歉,这不是一个修复程序,而是一种您可以更好地调试它的方法。

【讨论】:

    【解决方案4】:

    http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>

    你可以使用

    字体:300 12px/18px arial

    【讨论】:

      猜你喜欢
      • 2015-09-24
      • 2016-11-04
      • 1970-01-01
      • 2015-03-08
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      相关资源
      最近更新 更多