1

I'm trying to add FontAwesome icons to css pseudo elements

If I add the icon using html in the regular way it does work, but I'm trying to add the fonts to a bootstrap accordion so the icon changes in the collapsed state. That part works, but the icon is not showing. Instead there is a empty square in chrome and a square with the hex code in firefox.

Added kit (tried before and after css is loaded):

<script src="https://kit.fontawesome.com/30fc0982d8.js"></script>

CSS code:

#faq a:after{
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    content: '\f107';

}

#faq a.collapsed:after{
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    content: '\f106';
}

I would expect the icon to just show, but it doesn't. Any thoughts?

Edit: Forgot to add, I did some extensive searching on this and found several posts. Typically the solution was to add font-weight: 900, but as you can see I already did that.
Edit2: This question was marked duplicate but for FontAwesome with JS+SVG. I'm using the webfonts option.

cezar
  • 11,616
  • 6
  • 48
  • 84
GetShifting
  • 461
  • 4
  • 12

2 Answers2

0

as per the comment u need font awesome 5 this is the new code.

<style>
#faq a:after{
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  font-family: "Font Awesome 5 Pro";
  font-weight: 900;
  content: "\f078";

}
#faq a.collapsed:after{
  content: "\f077";
}
</style>
<section id="faq">
  <a></a>
  <a class="collapsed"></a>
</section>
<script src="https://kit.fontawesome.com/30fc0982d8.js""></script>
KuldipKoradia
  • 3,005
  • 7
  • 20
0

change the font-family name as below

   font-family: 'Font Awesome 5 Pro';

#faq a:after {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  font-family: 'Font Awesome 5 Pro';
  font-weight: 900;
  content: '\f107';
}

#faq a.collapsed:after {
  content: '\f106';
}
<script src="https://kit.fontawesome.com/30fc0982d8.js"></script>

<div id="faq">
  <a class=""> link</a>
  <br>

  <a class="collapsed"> collapsed link</a>

</div>
Soothran
  • 1,233
  • 4
  • 14