font-variation-settings

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

font-variation-settings CSS 描述符允许作者在 @font-face at-rule 中指定低级的 OpenType 或 TrueType 字体变体。此描述符的值与 font-variation-settings 属性相同,但全局关键字值除外。

由于此描述符在 @font-face at-rule 中设置字体对象的变体值,而不是设置整个元素的变体值,因此元素中只有部分字形可能使用此描述符渲染。

语法

css
/* Use the default settings */
font-variation-settings: normal;

/* Set values for OpenType axis names */
font-variation-settings: "xhgt" 0.7;

normal

文本使用默认设置进行布局。

<string> <number>

渲染文本时,OpenType 轴名称列表将传递给文本布局引擎以启用或禁用字体功能。每个设置始终是 4 个 ASCII 字符的 <string>,后跟一个指示轴值的 <number>。如果 <string> 字符数过多或过少,或者包含 U+20 - U+7E 码点范围之外的字符,则整个属性无效。<number> 可以是小数或负数。

正式定义

相关的 at-rule@font-face
初始值normal
计算值同指定值

正式语法

font-variation-settings = 
normal |
[ <string> <number> ]#

示例

在 @font-face 规则中设置字体粗细和拉伸

css
@font-face {
  font-family: "OpenTypeFont";
  src: url("open_type_font.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-variation-settings:
    "wght" 400,
    "wdth" 300;
}

规范

规范
CSS 字体模块第 4 级
# font-rend-desc

浏览器兼容性

另见