Lucide 是一个开源图标库,基于 Feather Icons 改进而来,提供 2000+ 高质量 SVG 图标,特点是:
CDN(Content Delivery Network)即内容分发网络。通过 CDN 引入 Lucide 图标,无需下载图标文件到本地,直接通过网络链接使用,优点是:
在 <head>
标签中加入 Lucide 的 CDN 链接:
<head>
<script src="https://cdn.jsdelivr.net/npm/lucide-static@0.279.0/dist/lucide.min.js"></script>
</head>
📌 版本说明:
0.279.0
是当前版本号,可在 Lucide CDN 页面 查看最新版本。
在需要显示图标的地方,添加 <i>
标签并指定图标名称(格式:lucide-图标名
):
<!-- 显示一个笑脸图标 -->
<i class="lucide-smile"></i>
<!-- 显示一个搜索图标 -->
<i class="lucide-search"></i>
Lucide 会自动将这些标签替换为对应的 SVG 图标。
可以通过 CSS 直接修改图标的大小、颜色、粗细等:
<!-- 大红色搜索图标 -->
<i class="lucide-search text-3xl text-red-500"></i>
<!-- 蓝色小图标(结合Tailwind CSS) -->
<i class="lucide-heart text-blue-500 h-5 w-5"></i>
text-3xl
:调整图标大小(Tailwind 字体大小类)text-red-500
:设置图标颜色(Tailwind 颜色类)h-5 w-5
:直接指定图标高度和宽度<!DOCTYPE html>
<html>
<head>
<!-- 引入 Tailwind CSS -->
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<!-- 引入 Lucide 图标 -->
<script src="https://cdn.jsdelivr.net/npm/lucide-static@0.279.0/dist/lucide.min.js"></script>
</head>
<body class="p-8">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-bold mb-4">
<i class="lucide-book text-green-500 mr-2"></i>
学习资源
</h2>
<div class="flex space-x-4 mt-4">
<button class="flex items-center bg-blue-500 text-white px-4 py-2 rounded-md">
<i class="lucide-download mr-2"></i>
下载资料
</button>
<button class="flex items-center bg-gray-200 text-gray-800 px-4 py-2 rounded-md">
<i class="lucide-share-2 mr-2"></i>
分享
</button>
</div>
</div>
</body>
</html>
lucide-home
:主页lucide-user
:用户lucide-settings
:设置lucide-mail
:邮件lucide-star
:星星lucide-check
:对勾lucide-x
:叉号完整图标列表可查看 Lucide 官方网站。
<head>
中。lucide-arrow-right
,而非 lucide-ArrowRight
。