Font Awesome 5 shows empty square when using the JS+SVG version

前端 未结 2 823
渐次进展
渐次进展 2020-11-22 08:08

Attempting to replace the bullet type on an list item tag with a Font Awesome icon but I am getting an empty square:

相关标签:
2条回答
  • 2020-11-22 08:14

    If you are using the CSS version read this: Font Awesome 5, why css content is not showing?

    Using the last release of the Font Awesome 5 you can enable the use of pseudo-element with the JS version by adding data-search-pseudo-elements like below:

    ul {
      list-style: none;
    }
    
    .testitems {
      line-height: 2em;
    }
    
    .testitems:before {
      font-family: "Font Awesome 5 Free";
      content: "\f058";
      display:none; /* We need to hide the pseudo element*/
    }
    /*target the svg for styling*/
    .testitems svg {
      color: blue;
      margin: 0 5px 0 -15px;
    }
    <script data-search-pseudo-elements src="https://use.fontawesome.com/releases/v5.13.0/js/all.js"></script>
    <ul>
      <li class="testitems">List Item 1</li>
      <li class="testitems">List Item 2</li>
      <li class="testitems">List Item 3</li>
      <li class="testitems">List Item 4</li>
      <li class="testitems">List Item 5</li>
    </ul>
    <i class="fa fa-user"></i>

    You can check the documentation for more details :

    If you’re using our SVG + JS framework to render icons, you need to do a few extra things:

    Enable Pseudo Elements

    Using CSS Pseudo elements to render icons is disabled by default when using our SVG + JS Framework. You’ll need to add the <script data-search-pseudo-elements ... > attribute to the <script /> element that calls Font Awesome.

    Set Pseudo Elements’ display to none

    Since our JS will find each icon reference (using your pseudo element styling) and insert an icon into your page’s DOM automatically, we’ll need to hide the real CSS-created pseudo element that’s rendered.

    0 讨论(0)
  • 2020-11-22 08:14

    As stated in the docs of Font Awesome of how to enable Pseudo class...

    ul {
      list-style: none;
    }
    
    .testitems {
      line-height: 2em;
    }
    
    .testitems::before {
      font-family: "Font Awesome 5 Solid";
      content: "\f058";
      display: none;
    }
    .user::before{
      font-family: "Font Awesome 5 Solid";
      content: "\f007";
      display: none;
    }
    <script>FontAwesomeConfig = { searchPseudoElements: true };</script>
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
    <ul>
      <li class="testitems">List Item 1</li>
      <li class="testitems">List Item 2</li>
      <li class="testitems">List Item 3</li>
      <li class="testitems">List Item 4</li>
      <li class="testitems">List Item 5</li>
    </ul>
    <i class="fa fa-user"></i><br>
    <a class="user" href="#">User</a>

    0 讨论(0)
提交回复
热议问题