如何仅下载使用Font Awesome v5剪贴板图标并解决v4与v5共存时图标显示方块问题
Hey there! Let's get that Font Awesome v5 clipboard icon working and fix those square placeholders once and for all. Here's a step-by-step solution tailored to your setup:
Since you only need the clipboard icon, download the Font Awesome 5 Free web package (it includes both solid and regular versions of the clipboard icon). Once downloaded, extract these specific font files from the fonts folder:
fa-solid-900.eotfa-solid-900.woff2fa-solid-900.wofffa-solid-900.ttffa-solid-900.svg
Place these files into your project's assets/fonts directory (you can keep old v4 files separate, or replace them if you no longer need v4 icons).
Font Awesome v5 changed font family names and file naming conventions, so your old v4 code won't work. Replace your existing @font-face block with this v5 version (for the solid clipboard icon):
@font-face { font-family: 'Font Awesome 5 Free'; font-style: normal; font-weight: 900; src: url("<%= asset_path 'fonts/fa-solid-900.eot' %>"); src: url("<%= asset_path 'fonts/fa-solid-900.eot?#iefix' %>") format('embedded-opentype'), url("<%= asset_path 'fonts/fa-solid-900.woff2' %>") format('woff2'), url("<%= asset_path 'fonts/fa-solid-900.woff' %>") format('woff'), url("<%= asset_path 'fonts/fa-solid-900.ttf' %>") format('truetype'), url("<%= asset_path 'fonts/fa-solid-900.svg#fontawesome' %>") format('svg'); }
If you want the hollow (regular) clipboard icon later, you'll need an additional @font-face block for the 400-weight font, but let's focus on getting the solid icon working first.
v5 uses style-specific prefixes (unlike v4's single fa prefix). For the solid clipboard icon, use this markup:
<i class="fas fa-clipboard"></i>
fas= Font Awesome Solid (matches the 900 weight in our @font-face)fa-clipboard= the unique identifier for the clipboard icon
If you still see squares after the above steps, troubleshoot these common issues:
- Check font file paths: Open your browser's DevTools > Network tab, reload the page, and ensure none of the font files return a 404 error. Adjust the
asset_pathin your @font-face if the path is incorrect. - Add required class styling: The
fasclass needs to map to the correct font family and weight. Add this snippet to your CSS:.fas { font-family: 'Font Awesome 5 Free'; font-weight: 900; } - Clear browser cache: Old v4 font data might be cached. Force a hard refresh (Ctrl+F5 on Windows, Cmd+Shift+R on Mac) or clear your browser's cache entirely.
- Remove v4 conflicts: If you still have v4's @font-face or CSS in your project, comment it out temporarily—v4 and v5 can clash if their font family names overlap.
That should get your clipboard icon displaying properly!
内容的提问来源于stack exchange,提问作者Bhim rav

