本文详解 anybody 变量字体中 `font-stretch` 失效的根本原因:google fonts 加载 url 中声明的 `wdth` 轴范围必须严格匹配字体实际支持的区间(anybody 仅支持 50–150),超出则导致轴被静默忽略
。
在使用 Google Fonts 提供的变量字体(Variable Fonts)时,仅在 CSS 中设置 font-stretch 并不足以激活宽度轴(wdth)效果——必须确保 @import 或 请求中声明的轴范围与字体实际支持范围完全一致。
以 Anybody 字体为例,其官方字体测试页明确标注:
✅ 支持的 wdth 范围为 50–150(50 表示极窄/condensed,100 为常规,150 为宽/extended)
❌ 若在 CSS @import 中错误写成 wdth=50..200,Google Fonts 服务将无法加载有效的可变字体文件,最终回退为静态字体子集(即不支持 font-stretch 的普通字体),导致 font-stretch: 50% 完全无效。
/* ✅ 正确:wdth 范围严格限定为 50..150 */
@import url('https://fonts.googleapis.com/css2?family=Anybody:wdth,50..150,wght,100..900&display=swap');
h1 {
font-family: 'Anybody', sans-serif;
font-weight: 900;
font-stretch: 50%; /* 等效于 wdth=50 → 极度压缩 */
}? 验证技巧:打开 Anybody 字体测试页,拖动「Width」滑块观察实际可调范围,或查看 Network 面板中加载的 font.woff2 文件响应头,确认 font-face 声明是否包含 font-stretch: 50% 150%。
应用上述修正后,