语法
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",
});
规范
| 规范 |
|---|
| CSS Properties and Values API Level 1> # inherits-descriptor> |