base-palette

Baseline 已广泛支持

此功能已成熟,可跨多种设备和浏览器版本使用。自 ⁨2022 年 11 月⁩起,所有浏览器均支持此功能。

base-palette CSS 描述符用于指定预定义调色板的名称或索引,以用于创建新调色板。如果指定的 base-palette 不存在,则将使用索引为 0 的调色板。

语法

css
@font-palette-values --one {
  base-palette: 1;
}

base-palette 描述符使用字体制造商创建的调色板的零基索引来指定。

<index>

指定要使用的预定义调色板的索引。

正式定义

相关的 at-rule@font-palette-values
初始值n/a(必需)
计算值同指定值

正式语法

base-palette = 
light |
dark |
<integer [0,∞]>

示例

更改字体中的默认调色板

使用 Rocher Color Font,此示例显示了两次将字体中的默认调色板切换到字体制造商创建的备用调色板。

HTML

html
<h2>default base-palette</h2>
<h2 class="two">base-palette at index 2</h2>
<h2 class="five">base-palette at index 5</h2>

CSS

css
@font-face {
  font-family: "Rocher";
  src: url("[path-to-font]/RocherColorGX.woff2") format("woff2");
}

h2 {
  font-family: "Rocher", fantasy;
}

@font-palette-values --two {
  font-family: "Rocher";
  base-palette: 2;
}

@font-palette-values --five {
  font-family: "Rocher";
  base-palette: 5;
}

.two {
  font-palette: --two;
}

.five {
  font-palette: --five;
}

结果

Example showing 3 different base-palettes of Rocher color font

规范

规范
CSS 字体模块第 4 级
# base-palette-desc

浏览器兼容性

另见