Font awesome 5 on pseudo elements

前端 未结 8 2035
面向向阳花
面向向阳花 2020-12-07 12:22

In font awesome 4 you could easily apply an icon to a :before/:after element using CSS.

Is the same possible with the new font awesome 5 JS/SVG implementation? As fr

8条回答
  •  一生所求
    2020-12-07 13:05

    Specifying the proper font-weight seems key to have some of the symbols displayed properly (and not "□□□" instead).

    font-weight has to be:

    • 400 for Regular and Brands symbols
    • 900 for Solid symbols
    • 300 for Light symbols

    I.e. if you use Font-Awesome with CSS + Webfonts, a CSS-only solution is:

    @import url("font-awesome/css/fontawesome-all.min.css"); /* FA CSS import */
    
    /* ... */
    
    .class:before {
        /* >> Symbol you want to use: */
        content: "\f16c";
        /* >> Name of the FA free font (mandatory), e.g.:
                   - 'Font Awesome 5 Free' for Regular and Solid symbols;
                   - 'Font Awesome 5 Pro' for Regular and Solid symbols (Professional License);
                   - 'Font Awesome 5 Brand' for Brands symbols. */
        font-family: 'Font Awesome 5 Free';
        /* >> Weight of the font (mandatory):
                   - 400 for Regular and Brands symbols;
                   - 900 for Solid symbols;
                   - 300 for Light symbols. */
        font-weight: 900;
    
        /* >> Optional styling: */
        display: inline-block;
        /* ... */
    }
    

提交回复
热议问题