大网数据广告活动
Web 标准与前端开发

CSSFontPaletteValuesRule

· 52CE 我爱测

The **`CSSFontPaletteValuesRule`** interface represents an @font-palette-values at-rule.

CSSOM

The CSSFontPaletteValuesRule interface represents an @font-palette-values at-rule.

Instance properties

Inherits properties from its ancestor CSSRule.

  • CSSFontPaletteValuesRule.name
    • : A string with the name of the font palette.
  • CSSFontPaletteValuesRule.fontFamily
    • : A string indicating the font families on which the rule has to be applied.
  • CSSFontPaletteValuesRule.basePalette
    • : A string indicating the base palette associated with the rule.
  • CSSFontPaletteValuesRule.overrideColors
    • : A string indicating the colors of the base palette that are overwritten and the new colors.

Instance methods

Inherits methods from its ancestor CSSRule.

Examples

Read associated font family using CSSOM

This example first defines an @import and an @font-palette-values at-rule. Then it reads the @font-palette-values rule and displays its name. The MDN live sample infrastructure combines all the CSS blocks in the example into a single inline style with the id css-output, so we first use document.getElementById() to find that sheet. The palette will be the second CSSRule in that stylesheet. So, rules[1] returns a CSSFontPaletteValuesRule object, from which we can access fontFamily.

HTML

<pre id="log">The @font-palette-values at-rule font families:</pre>

CSS

@import "https://fonts.googleapis.com/css2?family=Bungee+Spice";

@font-palette-values --Alternate {
  font-family: "Bungee Spice";
  override-colors:
    0 #00ffbb,
    1 #007744;
}

.alternate {
  font-palette: --Alternate;
}

JavaScript

const log = document.getElementById("log");

const rules = document.getElementById("css-output").sheet.cssRules;
const fontPaletteValuesRule = rules[1]; // aA CSSFontPaletteValuesRule interface
log.textContent += ` ${fontPaletteValuesRule.fontFamily}`;

Result

Read associated font family using CSSOM

Specifications

Browser compatibility

See also

  • @font-palette-values

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。