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

从Google Fonts导入的Sorts Mill Goudy字体在Sphinx中无法渲染求助

解决Sphinx Alabaster主题导入Google Fonts字体不生效的问题

问题原因

你仅定义了自定义字体的CSS类,但未将字体规则应用到页面实际元素,也未覆盖Alabaster主题的默认字体样式,同时静态资源文件放置目录有误,导致字体无法生效。

修复步骤

  1. 调整CSS文件位置
    将styles.css从_templates目录移至项目根目录下的_static目录(若_static不存在则新建),Sphinx默认从_static加载静态资源文件。

  2. 修改styles.css内容
    直接覆盖主题核心元素的字体规则,替换为目标字体:

    @import url('https://fonts.googleapis.com/css2?family=Sorts+Mill+Goudy:ital@0;1&display=swap');
    
    /* 覆盖页面正文、标题等核心文本元素的字体 */
    body, div.document, div.body, p, div.section h1, div.section h2, div.section h3, div.section h4, div.section h5, div.section h6 {
        font-family: "Sorts Mill Goudy", serif;
        font-weight: 400;
    }
    
    /* 单独设置斜体文本样式 */
    em, i, div.body em, div.body i {
        font-family: "Sorts Mill Goudy", serif;
        font-weight: 400;
        font-style: italic;
    }
    
  3. 清理缓存并重新构建
    在终端执行以下命令,避免旧构建缓存影响:

    make clean && make html
    

验证方法

打开构建后的HTML页面,右键选择「检查」,在Elements面板的Styles标签中查看对应元素的font-family属性,确认是否已设置为"Sorts Mill Goudy"。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 15:56:02