前端必知必会-CSS图标icon


CSS 图标

使用图标库,可以轻松将图标添加到 HTML 页面。

如何添加图标

将图标添加到 HTML 页面的最简单方法是使用图标库,例如 Font Awesome。

将指定图标类的名称添加到任何内联 HTML 元素(如 <i><span>)。

以下图标库中的所有图标都是可缩放矢量,可以使用 CSS 进行自定义(大小、颜色、阴影等)

Font Awesome 图标

要使用 Font Awesome 图标,请转到 fontawesome.com,登录并获取代码以添加到 HTML 页面的 <head> 部分:

<script src="https://kit.fontawesome.com/yourcode.js" crossorigin="anonymous"></script>

注意:无需下载或安装!

示例

<!DOCTYPE html>
<html>
<head>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
</head>
<body>

<i class="fas fa-cloud"></i>
<i class="fas fa-heart"></i>
<i class="fas fa-car"></i>
<i class="fas fa-file"></i>
<i class="fas fa-bars"></i>

</body>
</html>

结果:

Bootstrap 图标

要使用 Bootstrap 字形图标,请在 HTML 页面的 <head> 部分中添加以下行:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

注意:无需下载或安装!

示例

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<i class="glyphicon glyphicon-cloud"></i>
<i class="glyphicon glyphicon-remove"></i>
<i class="glyphicon glyphicon-user"></i>
<i class="glyphicon glyphicon-envelope"></i>
<i class="glyphicon glyphicon-thumbs-up"></i>

</body>
</html>

结果:
在这里插入图片描述

Google 图标

要使用 Google 图标,请在 HTML 页面的 ` 部分中添加以下行:

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

注意:无需下载或安装!

示例

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>

<i class="material-icons">cloud</i>
<i class="material-icons">favorite</i>
<i class="material-icons">attachment</i>
<i class="material-icons">computer</i>
<i class="material-icons">traffic</i>

</body>
</html>

结果:
在这里插入图片描述


总结

本文介绍了CSS图标icon的使用,如有问题欢迎私信和评论

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程岁月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值