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

16

我想在我的网站上使用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文件。

这是'as is'由服务器托管的public文件夹结构。

Public folder

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

i.material-icons.prefix perm_identity

我可以看到上面的CSS类被应用到了那个元素。

但是字体没有显示出来。

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


1
这里有同样的问题,但当我用来自Google存储库的图标替换了materialize.css提供的图标字体时,它就可以正常工作了。 我从以下链接下载了新的图标字体: https://github.com/google/material-design-icons/tree/master/iconfont - Hamid Reza Sepehr
3个回答

6
这是由于materializecss.com网站上的图标字体过时导致的,我使用了Google GH存储库中的字体,它们可以正常工作。

2

您可以直接在网页中使用 Google Material Design 图标。

详情请参见 https://google.github.io/material-design-icons/

我通过使用 Google 网页字体样式表解决了此问题。这种方法更加便捷,您只需在网页中包含样式表,所有 Web 字体图标类就会被加载,然后您就可以使用它们了。


1

只需将以下CSS链接添加到您的页面中,即可通过Google Web字体访问Material Design图标。

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

并指定您想要使用的图标。

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

更多详情请参考Material icon文档


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接