【问题标题】:Font Awesome 5, why is CSS content not showing?Font Awesome 5,为什么没有显示 CSS 内容?
【发布时间】:2023-03-09 22:55:02
【问题描述】:

我正在尝试在 CSS 的内容中使用 FontAwesome。

它与图标的代码一起出现,而不是图标。我已按照在线帮助进行操作,但仍然无法正常工作

css
  @font-face {
  font-family: 'FontAwesome';
  src: url('https://use.fontawesome.com/releases/v5.0.6/css/all.css'); 
}


.fp-prev:before {
    color:#fff;
    content: '/f35a';
    font-family: FontAwesome;
    font-style: normal;
    font-weight: normal;
    text-decoration: inherit;
}

【问题讨论】:

标签: css font-awesome pseudo-element font-awesome-5


【解决方案1】:

当你想包含 FontAwesome 时,你提供的 url 应该在head 标记内作为stylesheet 文件:

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.6/css/all.css">

然后你就可以像以前一样使用 Font Awesome。

【讨论】:

  • 我们根本不需要字体...只需 CSS 文件
  • @Gobbin 他问的是字体真棒而不是字体系列。
【解决方案2】:

如果您使用的是 JS+SVG 版本,请阅读:Font Awesome 5 shows empty square when using the JS+SVG version

首先,你只需要在head标签中包含Font Awesome 5的CSS文件:

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">

或在 CSS 文件中:

@import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css")

然后您需要更正 font-familycontent,如下所示:

@import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css");

.fp-prev:before {
    color:#000;
    content: '\f35a'; /* You should use \ and not /*/
    font-family: "Font Awesome 5 Free"; /* This is the correct font-family*/
    font-style: normal;
    font-weight: normal;
    font-size:40px;
}
&lt;i class="fp-prev"&gt;&lt;/i&gt;

在某些情况下,您还必须添加

font-weight:900

更多详情:Font Awesome 5 on pseudo elements shows square instead of icon


附带说明:Font Awesome 5 为每个图标包提供 4 个不同的font-family

Font Awesome 5 Free 获取免费图标。

Font Awesome 5 Brands 用于 Facebook、Twitter 等品牌图标。

@import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css");

.fp-prev:before {
  color: #000;
  content: "\f099";
  font-family: "Font Awesome 5 Brands";
  font-style: normal;
  font-weight: normal;
  text-decoration: inherit;
}
&lt;i class="fp-prev"&gt;&lt;/i&gt;

Font Awesome 5 ProFont Awesome Pro

Font Awesome 5 Duotone 也包含在 Pro 包中。

相关:Font Awesome 5 Choosing the correct font-family in pseudo-elements

【讨论】:

  • 需要图标的元素正在作为脚本的端口加载,因此我无法添加 标记。是否需要 i 标签?
  • @happycoding 不,这不是必需的,我只是用来展示类工作......你只需要使用类
  • 非常感谢,这是字体系列名称,我没有使用导入 css 作为字体。梦想成真!
  • 当我发现我已经找到的东西没有解决方案那么不容易时,我想给一千个赞。
  • @Temani Afif:感谢这个 sn-p。我几乎花了两个小时试图渲染一个字体真棒 5 图标,但不能,尽管正确地编写了 CSS 伪元素规则。您的链接声明解决了问题。但我有个问题。我怎么知道从哪里导入 Font Awesome 的 CSS 文件,尤其是哪个版本?尝试访问 use.fontawesome.com 不会导致任何地方。那么我怎么知道有哪些其他版本的 Font Awesome CSS 文件可用,我从哪里可以得到它们呢?请解释一下。
【解决方案3】:

我知道我真的迟到了。

您必须在标题中包含 Fontawesome CSS。

CDN -

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">

如果你已经下载了源文件,那么包括如下

<link rel="stylesheet" href="path-to-your-font-awesome-folder/css/all.min.css" />

稍后您必须按如下方式添加 CSS -

.fp-prev:before {
    color:#000;
    content: '\f35a'; /* replace / with \ */
    font-family: "Font Awesome 5 Free"; /* here is the correct font-family */
    font-style: normal;
    font-weight: 900;
    text-decoration: inherit;
}

如果你想通过&lt;i&gt;标签添加它,那么你可以关注

<i class="fas fa-arrow-alt-circle-right"></i>

确保您的字体粗细为 900。

参考 - https://github.com/FortAwesome/Font-Awesome/issues/11946

在 GitHub 中提出了同样的问题。他们建议对于纯字体真棒图标,font-weight 应该是900

希望对大家有所帮助。

【讨论】:

  • 你说接受的答案对你没有帮助:你能解释一下你的答案中没有在接受的答案中说的东西吗?如果我没记错的话,你基本上重复了一切
  • 在回答的最后,我添加了一个突出显示的注释以更改字体粗细。这就是我所说的变化。 GitHub 中也提出了字体粗细问题。请参考链接。你的回答真的没有帮助。在更改字体粗细时它起作用了。
  • 我不得不重复您在回答中所写的内容,因为这就是您显示任何图标的方式。如果我刚刚添加了字体粗细,它就不会那么具体了。无论如何,抱歉重复。
  • 我也在最后的答案中详细说明了字体粗细问题,就像您再次所做的一样。
【解决方案4】:

这也发生在我身上。我用过这个图标:就像使用 font awesome 5 cdn。

但是当我尝试选择同一个类然后编辑图标时,css 编辑没有在图标上运行。

因此,从 css 选择器上的“.fas fa-plus-square”中删除了“fas”,并将其改为“.fa-plus-square{}”。

所以 CSS 是这样的(对我来说):.fa-plus-square{ float: right; } 我删除了“fas”。它对我有用。

Html 类在哪里&lt;i class="fas fa-plus-square"&gt;&lt;/i&gt;

还有我使用的 CDN:“https://use.fontawesome.com/releases/v5.0.7/css/all.css”。 希望对你有帮助

【讨论】:

    【解决方案5】:

    让你的font-weight: 900;。我看你想念它

    【讨论】:

      【解决方案6】:

      由于颜色问题,这没有显示。请按照以下步骤操作:-

      Step- 1. 在您的页面中复制此样式

      &lt;link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css"&gt;

      第 2 步。将此代码复制到页面中 all.css 的顶部。

      @import url("https://use.fontawesome.com/releases/v5.14.0/css/all.css"); 
      

      Step- 3. 使用 font-family 以及 contentcolor like

         .password_invalid:before {
              color: #ff0000;
              content: '\f058';                     /* You should use \ and not /*/
              font-family: "Font Awesome 5 Free";  /* This is the correct font-family*/
              position: relative;
              margin-left: -36px;
              padding-right: 13px;
              font-weight: 400;
          }

      【讨论】:

        猜你喜欢
        • 2019-12-01
        • 1970-01-01
        • 2020-05-07
        • 1970-01-01
        • 2023-01-29
        • 2014-01-13
        • 2018-11-11
        • 2019-03-09
        相关资源
        最近更新 更多