怎么在div::after中添加一个font-class图标
时间: 2024-02-13 12:07:21 浏览: 83
可以在 `content` 属性中使用 Unicode 编码来添加字体图标。Font Awesome 使用的 Unicode 编码可以在它的网站上找到。例如,搜索图标的 Unicode 编码为 `f002`。
示例代码如下:
```css
div::after {
font-family: "Font Awesome 5 Free";
content: "\f002";
}
```
上述代码会在每个 `div` 元素的内容后面添加一个搜索图标。需要注意的是,你需要指定正确的字体名称,以及正确的 Unicode 编码。另外,为了让图标正常显示,你需要将 `display` 属性设置为 `inline-block`,并设置其宽度和高度。
完整的代码如下:
```html
<!-- 引入 Font Awesome 字体库 -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css">
<!-- 添加搜索图标 -->
<div>
搜索
<span class="search-icon"></span>
</div>
<style>
.search-icon::after {
font-family: "Font Awesome 5 Free";
content: "\f002";
display: inline-block;
width: 16px;
height: 16px;
margin-left: 5px;
}
</style>
```
上述代码会在一个 `div` 元素内添加一个文本和一个搜索图标。你可以根据实际情况进行调整。
阅读全文
相关推荐


















