继承性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

inherits CSS 描述符在使用@property at-rule时是必需的,它控制由 @property声明注册的自定义属性默认情况下是否会被继承。

Syntax(类型描述符)

css
@property --property-name {
  syntax: "<color>";
  inherits: false;
  initial-value: #c0ffee;
}

@property --property-name {
  syntax: "<color>";
  inherits: true;
  initial-value: #c0ffee;
}

取值

true

属性默认继承

false

属性默认不继承

规范定义

Related at-rule@property
初始值auto
计算值as specified

标准语法

css
inherits =   true   |  false  

实例

--my-color 自定义属性添加颜色值类型检测、设置默认值并且设置属性值不允许被继承。

使用 CSS @property @规则:

css
@property --my-color {
  syntax: "<color>";
  inherits: false;
  initial-value: #c0ffee;
}

使用 JavaScript 中的 CSS.registerProperty (en-US)函数:

js
window.CSS.registerProperty({
  name: "--my-color",
  syntax: "<color>",
  inherits: false,
  initialValue: "#c0ffee",
});

规范

Specification
CSS Properties and Values API Level 1
# inherits-descriptor

浏览器兼容性

BCD tables only load in the browser

参见