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

求助:@font-face在GitHub Pages中无法生效的问题排查

Troubleshooting @font-face Not Working on GitHub Pages (Works Locally)

Hey there! Let’s dig into why your custom fonts aren’t loading on GitHub Pages when they work perfectly locally. I’ve looked at your repo and live site, so here are the key fixes to test out:

  • Double-check font file paths
    Local file systems can be forgiving with paths, but GitHub Pages follows strict relative/root path rules. If your CSS is in a subfolder (like /css/style.css) and fonts are in /fonts/, make sure your src path is relative to the CSS file—for example, ../fonts/your-font.ttf instead of just fonts/your-font.ttf. You can also use the full project root path (since GitHub Pages serves from your repo name): /StarWarsRPG/fonts/your-font.ttf. To confirm, open your browser’s DevTools > Network tab, filter for font files, and check if any return a 404 error (that means the path is wrong).

  • Fix case sensitivity issues
    GitHub runs on Linux, which is case-sensitive for file names—unlike Windows/macOS (by default). If your @font-face code references StarJedi.ttf but the actual file in your repo is starjedi.ttf, GitHub Pages will throw a 404. Go through your CSS and repo files to make sure every letter’s case matches exactly.

  • Validate your @font-face syntax
    Make sure you’re including all necessary font formats (woff2, woff, ttf are the most widely supported) and that each src entry has the correct path and format declaration. For example:

    @font-face {
      font-family: 'StarJedi';
      src: url('../fonts/StarJedi.woff2') format('woff2'),
           url('../fonts/StarJedi.woff') format('woff'),
           url('../fonts/StarJedi.ttf') format('truetype');
      font-weight: normal;
      font-style: normal;
    }
    

    Also, ensure the font-family name you use in your CSS (like font-family: 'StarJedi';) matches exactly what’s defined in @font-face.

  • Verify GitHub Pages deployment status
    Sometimes deployments fail silently. Head to your repo’s Settings > Pages and check the deployment status at the top. If there’s an error message, follow its instructions to fix the issue (like missing files or build errors).

  • Clear browser cache
    Your browser might be holding onto an old version of your CSS file that doesn’t have the correct font paths. Try a hard refresh (Ctrl+Shift+R on Windows, Cmd+Shift+R on Mac) or open your site in incognito mode to rule out caching.

内容的提问来源于stack exchange,提问作者Brooke Mortensen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:17:30