材料设计图标未显示在浏览器中

新手上路,请多包涵

我正在尝试为我的网站托管 Google Material Design 图标集,但是我无法在 Chrome 或 Safari 中显示这些图标。

我正在使用这个 CSS 文件:

 @font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(/public/dist/font/Material-Design-Icons.eot); /* For IE6-8 */
  src: url(/public/dist/font/Material-Design-Icons.woff2) format('woff2'),
       url(/public/dist/font/Material-Design-Icons.woff) format('woff'),
       url(/public/dist/font/Material-Design-Icons.ttf) format('truetype');
}

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;  /* Preferred icon size */
  display: inline-block;
  width: 1em;
  height: 1em;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;

  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;

  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;

  /* Support for IE. */
  font-feature-settings: 'liga';
}

拉入文件:

 link(rel="stylesheet", href="/public/dist/css/font.css")

我可以在浏览器中看到的已加载

字体本身甚至被加载到页面中,我可以在 Chrome 的网络选项卡中看到 .woff 文件。

这是服务器“按原样”托管的 public 文件夹结构

公共文件夹

我在这里使用字体(玉):

 i.material-icons.prefix perm_identity

我可以看到上面的 CSS 类应用于该元素

但是字体不渲染。

编辑:这里的人有同样的问题: https ://github.com/google/material-design-icons/issues/205

原文由 rcjsdev 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 546
1 个回答

只需将以下 CSS 链接添加到您的页面,并通过 Google 网络字体访问材料设计图标。

 <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
  rel="stylesheet">

并指定您要使用的图标。

 <span class="material-icons">face</span>

有关更多详细信息,请参阅 材质图标文档

原文由 aparna_shelar 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题