【问题标题】:Font-awesome icons not displaying correctly字体很棒的图标无法正确显示
【发布时间】:2021-03-25 19:27:56
【问题描述】:

字体真棒图标最近停止显示。它们只是到处都是这样的小盒子:

这是这个特定组件中的图标:

<i class="fas fa-trash-alt fa-lg"></i>

我刚刚尝试在他们的网站上使用他们的“工具包”将 Font Awesome 更新到版本 5:https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4

这只是告诉您将其插入到您的 head 标签中:

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

我已经完成了(因为我使用的是 Angular,我已将其放在 index.html 文件中)但图标仍如上所示显示。我在这里做错了什么?

【问题讨论】:

  • 我认为是这样的
  • 感谢您的回复。这与我已经拥有的方式不完全一样吗?
  • 欢迎提出任何问题。如果我的回复对您有帮助,您可以将其标记为答案,以简化用户日后的搜索。 How does accepting an answer work?

标签: html css angular font-awesome


【解决方案1】:

Let's look at docs how icons can be shown。所以我们可以这样输入:

<fa-icon [icon]="['far', 'square']"></fa-icon>
<br>
<fa-icon [icon]="['far', 'check-square']"></fa-icon>

The complete stackblitz example can be seen here

更新:

necessary to install:

  npm install @fortawesome/fontawesome-svg-core
$ npm install @fortawesome/free-solid-svg-icons
# See Compatibility table below to choose a correct version
$ npm install @fortawesome/angular-fontawesome@<version>

你的app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faSquare, faCheckSquare } from '@fortawesome/free-solid-svg-icons';
import { faSquare as farSquare, faCheckSquare as farCheckSquare } from 
  '@fortawesome/free-regular-svg-icons';
import { faStackOverflow, faGithub, faMedium } from 
  '@fortawesome/free-brands-svg-icons';

import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';

@NgModule({
  imports:      [ BrowserModule, FormsModule, FontAwesomeModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule {
  constructor() {
    library.add(faSquare, faCheckSquare, farSquare, farCheckSquare, 
      faStackOverflow, faGithub, faMedium);
  }
}

然后app.component.html

<div style="text-align:center">
  <h2>Using Solid Icons</h2>
  <fa-icon [icon]="['fas', 'square']"></fa-icon>
  <br>
  <fa-icon [icon]="['fas', 'check-square']"></fa-icon>
</div>

【讨论】:

  • @BailP 很高兴它对你有所帮助:)
【解决方案2】:

FontAwesome 4.7.0 包含fa-trash-alt 图标。

FontAwesome 5 确实包含fa-trash-alt图标。

因此,如果您包含 FontAwesome 版本 5+fa-trash-alt 应该可以按预期工作:

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet"/>
<i class="fas fa-trash-alt fa-lg"></i>

【讨论】:

  • 感谢您的回复。我已将您在上面提供的链接添加到我的 index.html 文件中的 head 标记中,但同样的问题仍然存在(图标在图像中显示如上)
  • 由于您使用的是 Angul,请尝试使用 fa 而不是 fas。比如:&lt;i class="fa fa-trash-alt fa-lg"&gt;&lt;/i&gt;
  • 我也试过了,结果还是一样
猜你喜欢
  • 2014-03-07
  • 2014-02-17
  • 1970-01-01
  • 2012-05-25
  • 2021-10-16
  • 2019-01-27
  • 2020-01-07
  • 2015-04-06
  • 2015-12-01
相关资源
最近更新 更多