在网页中使用字体图标:Material design icons
CSS3支持使用自定义字体模块,具体语法如下
@font-face {
font-family: <YourWebFontName>;
src: <source> [<format>][,<source> [<format>]]*;
[font-weight: <weight>];
[font-style: <style>];
}
h1 {
font-family: <YourWebFontName>;
}
是不是很简单.Google也开源了一套字体图标文件,Material design icons,字体使用Apache License Version 2.0协议.
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(https://example.com/MaterialIcons-Regular.eot); /* For IE6-8 */
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(https://example.com/MaterialIcons-Regular.woff2) format('woff2'),
url(https://example.com/MaterialIcons-Regular.woff) format('woff'),
url(https://example.com/MaterialIcons-Regular.ttf) format('truetype');
}
.material-icons {
font-family: '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;
/* 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';
}
在需要的地方使用:
<i class="material-icons">face</i>
<!-- 或者 -->
<i class="material-icons"></i>
你可以向操作普通字体一样,设置图标,宽度高度,行距.项目介绍:http://google.github.io/material-design-icons/,查看所有图标:https://material.io/icons/