--- title: '继承性' slug: Web/CSS/@property/inherits tags: - CSS - Reference - Web - Property - Houdini ---
inherits CSS 描述符在使用{{cssxref("@property")}} {{cssxref("at-rule")}}时是必需的,它控制由 @property声明注册的自定义属性默认情况下是否会被继承。
@property --property-name {
syntax: '<color>';
inherits: false;
initial-value: #c0ffee;
}
@property --property-name {
syntax: '<color>';
inherits: true;
initial-value: #c0ffee;
}
truefalse{{cssinfo}}
{{csssyntax}}
为 --my-color {{cssxref('--*', '自定义属性')}}添加颜色值类型检测、设置默认值并且设置属性值不允许被继承。
使用 CSS {{cssxref('@property')}} @规则:
@property --my-color {
syntax: '<color>';
inherits: false;
initial-value: #c0ffee;
}
使用 JavaScript中的 {{domxref('CSS.registerProperty')}}函数:
window.CSS.registerProperty({
name: '--my-color',
syntax: '<color>',
inherits: false,
initialValue: '#c0ffee',
});
| 规范 | 状态 | 提议 |
|---|---|---|
| {{SpecName('CSS Properties and Values API', '#inherits-descriptor', 'inherits')}} | {{Spec2('CSS Properties and Values API')}} | 初始定义. |
{{Compat("css.at-rules.property.inherits")}}