【问题标题】:How can we use Font Awesome Icon in CSS? I want to display an icon after heading我们如何在 CSS 中使用 Font Awesome Icon?我想在标题后显示一个图标
【发布时间】:2021-10-07 18:24:55
【问题描述】:

我们如何在 CSS 中使用 Font Awesome Icon?我想在标题后显示一个图标。 我想稍微自定义一下我的标题,这样标题后面就会有一个图标。

这是我的代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
        integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />

    <title>Test</title>

    <style>
        * {
            margin: 0;
            padding: 0%;
            box-sizing: border-box;
        }

        .main-div {
            width: 100vw;
            height: 100vh;
            padding-top: 100px;
            text-align: center;
        }

        h1 {
            color: #2980b9;
            font-size: 5rem;
        }

        h1::after {
            font-family: "Font Awesome 5 Free";
            font-weight: 900;
            content: "\f007";
            width: 20vh;
            height: 25px;
            color: #1abc9c;
            font-size: 3rem;
            display: inline-block;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <section class="main-div">
        <h1>Test</h1>
    </section>
</body>

</html> 

但是,图标没有出现。另外,如何使用 css 显示该图标?

任何帮助将不胜感激!

【问题讨论】:

  • 该样式表不包含Font Awesome 5 free的声明

标签: html css bootstrap-4 font-awesome-5


【解决方案1】:

您可以将Font Awesome 5 Free 替换为Font Awesome 5 Pro

您的代码如下所示:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
        integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />

    <title>Test</title>

    <style>
        * {
            margin: 0;
            padding: 0%;
            box-sizing: border-box;
        }

        .main-div {
            width: 100vw;
            height: 100vh;
            padding-top: 100px;
            text-align: center;
        }

        h1 {
            color: #2980b9;
            font-size: 5rem;
        }

        h1::after {
            font-family: "Font Awesome 5 Pro";
            font-weight: 900;
            content: "\f007";
            width: 20vh;
            height: 25px;
            color: #1abc9c;
            font-size: 3rem;
            display: inline-block;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <section class="main-div">
        <h1>Test</h1>
    </section>
</body>

</html> 

【讨论】:

    猜你喜欢
    • 2013-01-22
    • 1970-01-01
    • 2013-02-11
    • 2016-12-12
    • 2021-07-14
    • 2017-05-24
    • 2013-05-10
    • 2022-12-25
    • 1970-01-01
    相关资源
    最近更新 更多