inherits

Limited availability

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

inherits CSS 描述符是在使用 @property At 规则时所必须的,它控制着由 @property 指定的自定义属性注册是否默认继承。

语法

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

形式语法

inherits = 
true |
false

示例

--my-color 自定义属性添加类型检查,将其限定为颜色类型,并设置默认值,同时禁止其继承值。

使用 CSS @property At 规则

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

使用 JavaScript CSS.registerProperty()

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

参见