2019 年更新在这里:
自行托管您的材料图标,常规图标、圆形图标、尖锐图标、所有变体图标。
从这个 repo 中获取它们:
https://github.com/petergng/material-icon-font
出于某种原因,我不知道为什么这些字体不容易从 Google 存储库中访问。
但是给你。
下载软件包后,进入 bin 文件夹,您将看到四个变体。
当然,这取决于您使用哪个。
要使用它们,请创建一个 css 文件并
- 为您需要的每个变体生成字体:
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(./icons/regular/Material-Icons-Regular.eot); /* For IE6-8 */
src: local('Material-Icons-Regular'),
url(./icons/regular/Material-Icons-Regular.woff2) format('woff2'),
url(./icons/regular/Material-Icons-Regular.woff) format('woff'),
url(./icons/regular/Material-Icons-Regular.ttf) format('truetype');
}
@font-face {
font-family: 'Material Icons Round';
font-style: normal;
font-weight: 400;
src: url(./icons/round/Material-Icons-Round.eot); /* For IE6-8 */
src: local('Material-Icons-Round'),
url(./icons/round/Material-Icons-Round.woff2) format('woff2'),
url(./icons/round/Material-Icons-Round.woff) format('woff'),
url(./icons/round/Material-Icons-Round.svg) format('svg'),
url(./icons/round/Material-Icons-Round.ttf) format('truetype');
}
@font-face {
font-family: 'Material Icons Sharp';
font-style: normal;
font-weight: 400;
src: url(./icons/sharp/Material-Icons-Sharp.eot); /* For IE6-8 */
src: local('Material-Icons-Sharp'),
url(./icons/sharp/Material-Icons-Sharp.woff2) format('woff2'),
url(./icons/sharp/Material-Icons-Sharp.woff) format('woff'),
url(./icons/sharp/Material-Icons-Sharp.svg) format('svg'),
url(./icons/sharp/Material-Icons-Sharp.ttf) format('truetype');
}
url 将链接到图标在项目中的位置。
- 现在让我们注册图标类:
.material-icons-outlined, .material-icons {
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
}
这将使两者
.material-icons-outlined,
和
.material-icons 类使用相同的默认值。
如果要使用.material-icons-sharp,只需将其附加到两个类名即可。
- 最后,让我们插入您从第 1 步中提取的字体。
.material-icons {
font-family: 'Material Icons';
}
.material-icons-outlined {
font-family: 'Material Icons Outline';
}
同样,要使用更多变体,比如 Sharp,只需像上面两个一样添加它的块。
完成后...转到您的 html 并使用新创建的图标。
<i class="material-icons-outlined">hourglass_empty</i>
<i class="material-icons">phone</i>