惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
L
LangChain Blog
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
WordPress大学
WordPress大学
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
美团技术团队
Jina AI
Jina AI
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
D
Docker

皓子的小站

糟糕的 meta name="theme-color" How to Automatically Track Newly Supported ESLint Rules in Oxlint How to Gradually Migrate from ESLint to Oxlint (Without Breaking Everything) 静态资源预压缩:零运行时开销,极致节省带宽 CVE-2025-70886 Proof of Concept (PoC) | A Script to Crash Halo CMS Comment Backend 自定义网页鼠标指针——一段曲折的旅程 CVE-2025-70886 漏洞复现/PoC | 一个脚本让 Halo CMS 评论后台瘫痪 2025 年终总结 & 博客两周年 老用户专享!已有 Halo 专业版授权可免费升级商业版 自动追踪 Oxlint 对 ESLint 规则的新增支持 Halo 贡献者证书与实体周边盲盒开箱 博客评论系统指南 CDN 回源跟随配置导致登录异常问题排查 SCDN 免费赞助计划:助力高质量博客&博客圈 锐捷校园网:网络共享与带宽叠加方案(哈理工案例) ESLint 到 Oxlint 渐进式迁移快速上手指南 Fixing Vite Breaking Inline JS & CSS in Thymeleaf Templates 解决 Vite 破坏 Thymeleaf 模板内联 JS & CSS 的方法 我的博客,为什么是月更? 博客俱乐部一周年纪念品开箱 网站字体加载之坑——format 篇 经历 1000000000 次 DDoS 请求攻击后,我总结了三条经验 题解分享:[AtCoder Beginner Contest 414 E] Count A%B=C 题解分享:[蓝桥杯 2025 国 Python A] 杨辉三角 P12876 FiF口语训练破解刷分教程(适用于 Windows) 不要与蠢人辩论 小心网络地雷·续篇 当心网络组织“开往”·续篇 当心网络组织“开往” 小心网络地雷
网站字体应用之&...
HowieHz · 2026-04-04 · via 皓子的小站

今天一位博客朋友向我反映:在使用我站点主题后行内代码块(code 标签)不能正常加载自定义字体。

定位问题

打开开发人员工具切换到“元素”面板,选择“已计算”。选择指定段落文字,在“已计算”搜索框随机输入字符以过滤属性值,即可看到最底下的“呈现的字体”。

我发现“呈现的字体”并非设定的字体,而是本地来源的 NSimSun(新宋体)。

保持在“元素”面板,选择“样式”,搜索 font-family
发现 code 标签并未应用我设定的 body { font-family: ... },而是应用了用户代理样式表的 code { font-family: monospace }

发现问题

我再次从用户代理样式表学习。

来自 Chromium 的:

tt, code, kbd, samp {
    font-family: monospace
}

pre, xmp, plaintext, listing {
    display: block;
    font-family: monospace;
    white-space: pre;
    margin: 1__qem 0
}

来自 Firefox 的:

tt,
code,
kbd,
pre,
samp,
listing,
xmp,
plaintext {
  font-family: -moz-fixed;
  /* Replace this with text-spacing:none when the shorthand is implemented: */
  text-autospace: no-autospace;
}

解决问题

问题已经很清楚了,只需要在原本的 body 指定外:

body {
  font-family: ...;
}

再给以下元素设置 font-family: inherit; 后,它们就会正常继承页面字体。

tt, code, kbd, samp, pre, xmp, plaintext, listing {
  font-family: inherit;
}

此外,也可以为它们单独设置等宽字体(monospace)。