inherits
Baseline
2024
Newly available
Since July 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or 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;
}
值
形式定义
形式语法
inherits =
true |
false
示例
为 --my-color
自定义属性添加类型检查,将其限定为颜色类型,并设置默认值,同时禁止其继承值。
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> |
浏览器兼容性
Loading…