继承性
Syntax(类型描述符)
css
@property --property-name {
syntax: "<color>";
inherits: false;
initial-value: #c0ffee;
}
@property --property-name {
syntax: "<color>";
inherits: true;
initial-value: #c0ffee;
}
取值
规范定义
标准语法
css
inherits = true | false
实例
为 --my-color
自定义属性
添加颜色值类型检测、设置默认值并且设置属性值不允许被继承。
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