Home > Article > Web Front-end > How to Use Font Awesome Icons as CSS Content?
Use Font Awesome Icons as CSS Content
In using Font Awesome icons as CSS content, avoid embedding HTML code directly within the content property. Instead, follow these steps:
FontAwesome 5:
a:before { font-family: "Font Awesome 5 Free"; content: "\f095"; display: inline-block; padding-right: 3px; vertical-align: middle; font-weight: 900; }
FontAwesome 4 and Below:
a:before { font-family: FontAwesome; content: "\f095"; }
For spacing between the icon and text:
a:before { font-family: FontAwesome; content: "\f095"; display: inline-block; padding-right: 3px; vertical-align: middle; }
To change the icon on hover:
a:hover:before { content: "\f099"; }
Consider setting a fixed width on the base icon declaration to prevent nudging due to different icon sizes.
The above is the detailed content of How to Use Font Awesome Icons as CSS Content?. For more information, please follow other related articles on the PHP Chinese website!