Use FontAwesome or Glyphicons with css :before

前端 未结 8 927
小蘑菇
小蘑菇 2020-12-07 10:59

Is there any way to embed HTML in the css content: element when using a :before pseudo-element?

I want to use a Font Awesome (or Glyphicon)

8条回答
  •  鱼传尺愫
    2020-12-07 11:45

    The accepted answer (as of 2019 JULY 29) is only still valid if you have not started using the more recent SVG-with-JS approach of FontAwesome. In which case you need to follow the instructions on their CSS Pseudo-Elements HowTo. Basically there are three things to watch out for:

    • place the data-attribute on the SCRIPT-Tag "data-search-pseudo-elements" loading the fontawesome.min.js
    • make the pseudo-element itself have display:none
    • proper font-family & font-weight combination for the icon you need: "Font Awesome 5 Free" and 300 (fal/light), 400 (far/regular) or 900 (fas/solid)

提交回复
热议问题