iconfont的图标使用Unicode格式的实现

一:准备

  1. 将自己需要的图标添加到自己的项目中,如下图所示:
    在这里插入图片描述

  2. 将图标文件下载到本地
    在这里插入图片描述

二:使用

  1. 复制项目里提供的@font-face
    在这里插入图片描述
  2. 具体的使用
    方式一:用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: "&#xe658;"; 无效*/
                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">&#xe658;</i>
                </td>
            </tr>
            <tr>
                <td>icon-setting</td>
                <td>& #xe78e;</td>
                <td>
                    <i class="iconfont">&#xe78e;</i>
                </td>
            </tr>
        </table>
        <br />
        <!-- 方式二: -->
        <h2>通过伪元素添加图标</h2>
        <div class="icon-after">这里的后面加上图标</div>
    </body>
</html>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值