You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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 src properties: You’re declaring src multiple 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 single src line separated by commas.
  • Typos in font name: The official font family name is FontAwesome (note the trailing "e"), but you’ve written FontAwsome—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-weight and font-style ensures 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

  1. 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.
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:12:51