ascent-override 仅覆盖字体 ascent 度量值,不改变 font-size 或 line-height 计算,须与 descent-override、line-gap-override 联用,并关闭 font-optical-sizing;仅 chromium 125+ 支持,需在 font-display: swap 回退时强制替换为首个回退字体测试。

ascent-override 不是调 font-size,而是对齐字体度量线
它不改变文字大小,也不影响 line-height 计算逻辑,只覆盖自定义字体内部的 ascent 值(即从基线到字形最高点的距离)。如果设错,轻则文字视觉下沉/上浮,重则字母顶部被裁切(比如带重音符号的 é、上标数字)。
必须配合 descent-override 和 line-gap-override 一起用
单独调 ascent-override 几乎无效,因为布局偏移由三者共同决定:
-
ascent-override控制上边界(基线到顶部) -
descent-override控制下边界(基线到底部,注意:值为正数,越大文字越上浮) -
line-gap-override控制行间空隙(影响line-height: normal下的实际行高)
例如回退字体是 "SF Pro Text",你得先用工具(如 font-bakers 或 Chrome 的 Font Inspector)查出它的 ascent/descent/lineGap 占 em 的百分比,再按比例填进三个 override。
Chrome 125+ 才支持,且 font-optical-sizing 必须关掉
这几个属性在 Safari / Firefox 中完全不识别,仅 Chromium 系(Chrome、Edge、新版 Opera)支持。启用前务必加:
@font-face {
font-family: "MyFont";
src: url("myfont.woff2");
font-display: swap;
font-optical-sizing: none; /* 不加这句,ascent-override 可能被忽略 */
ascent-override: 94%;
descent-override: 27%;
line-gap-override: 0%;
}
漏掉 font-optical-sizing: none 是最常被忽略的坑——Chromium 默认开启光学缩放,会干扰度量覆盖行为。
测试时必须 Force substitution 到首个回退字体
浏览器只在 font-display: swap 触发回退阶段才应用这些 override,而它只作用于字体栈中第一个可用的回退字体。比如:
font-family: "MyFont", "SF Pro Text", system-ui;
你要在 DevTools → Rendering 面板里强制把字体替换成 "SF Pro Text"(不是 system-ui),再开 Layout Shift Regions 观察红框抖动是否收敛。硬刷新后逐次微调 ascent-override 值(±0.5% 起步),过调(如设成 110%)反而会让文字加载后“塌下来”,放大 CLS。
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!











