在CSS中引入FontAwesome字体的配置咨询:我的代码是否正确?
Fixing Your FontAwesome @font-face Setup
Hey there! Let's walk through the issues in your current configuration and get it working properly:
Key Problems in Your Code
- Overwritten
srcproperties: You’re declaringsrcmultiple times, which means only the last one will take effect—browsers won’t try loading any of the previous font files. All font sources should be listed in a singlesrcline separated by commas. - Typos in font name: The official font family name is
FontAwesome(note the trailing "e"), but you’ve writtenFontAwsome—this mismatch will prevent the browser from recognizing the font when you reference it later. - Incorrect format value for OTF: The valid format string for OpenType fonts is
'opentype', not'otf'. - Missing font weight/style: Adding explicit
font-weightandfont-styleensures the font renders consistently across different text styles.
Corrected Configuration
Here’s the fixed code, with comments explaining the changes:
@font-face { font-family: 'FontAwesome'; /* Fixed the typo in font name */ src: url('./webagency_images/fonts/fontawesome-webfont.eot'); src: url('./webagency_images/fonts/fontawesome-webfont.eot?#iefix') format('embedded-opentype'), /* IE8+ compatibility */ url('./webagency_images/fonts/fontawesome-webfont.woff') format('woff'), url('./webagency_images/fonts/fontawesome-webfont.ttf') format('truetype'), url('./webagency_images/fonts/fontawesome-webfont.svg#FontAwesome') format('svg'), url('./webagency_images/fonts/FontAwesome.otf') format('opentype'); /* Corrected format value */ font-weight: normal; /* Ensures consistent weight */ font-style: normal; /* Ensures consistent style */ }
Quick Checks to Verify
- File Paths: Double-check that your CSS file’s relative path to the
webagency_images/fonts/folder is correct. For example:- If your CSS is in
css/style.css, the path should be../webagency_images/fonts/(to navigate up one level from the css folder). - If your CSS is in the root directory,
./webagency_images/fonts/is correct.
- If your CSS is in
- Filename Matching: Confirm that the filenames in your code exactly match the actual font files in your folder (case matters on some servers!).
内容的提问来源于stack exchange,提问作者Voodoobear
相关产品推荐
相关产品推荐

