一:准备
-
将自己需要的图标添加到自己的项目中,如下图所示:
-
将图标文件下载到本地
二:使用
- 复制项目里提供的@font-face
- 具体的使用
方式一:用i标签
方式二:通过伪元素添加图标
三:代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>iconfont的Unicode使用</title>
<style>
html,
body {
height: 100%;
}
table,
th,
td {
border: 1px solid black;
}
@font-face {
font-family: "iconfont"; /* Project id 3013887 */
src: url("./fonts/font_3013887_w4gpn5az95j.woff2")
format("woff2"),
url("./fonts/font_3013887_w4gpn5az95j.woff") format("woff"),
url("./fonts/font_3013887_w4gpn5az95j.ttf")
format("truetype");
}
/* 方式一: */
.iconfont {
font-family: "iconfont";
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
-moz-osx-font-smoothing: grayscale;
}
/* 方式二: */
.icon-after::after {
font-family: "iconfont";
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
/* content: ""; 无效*/
content: "\e658;"; /* 有效 */
}
</style>
</head>
<body>
<h2>我test项目里的icon</h2>
<!-- 方式一: -->
<table>
<tr>
<th>名称</th>
<th>图标代码</th>
<th>图标</th>
</tr>
<tr>
<td>icon-checkbox-checked</td>
<td>& #xe658;</td>
<td>
<i class="iconfont"></i>
</td>
</tr>
<tr>
<td>icon-setting</td>
<td>& #xe78e;</td>
<td>
<i class="iconfont"></i>
</td>
</tr>
</table>
<br />
<!-- 方式二: -->
<h2>通过伪元素添加图标</h2>
<div class="icon-after">这里的后面加上图标</div>
</body>
</html>