From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/inherit/index.html | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 files/zh-cn/web/css/inherit/index.html (limited to 'files/zh-cn/web/css/inherit') diff --git a/files/zh-cn/web/css/inherit/index.html b/files/zh-cn/web/css/inherit/index.html new file mode 100644 index 0000000000..5bad2ead9c --- /dev/null +++ b/files/zh-cn/web/css/inherit/index.html @@ -0,0 +1,79 @@ +--- +title: inherit +slug: Web/CSS/inherit +tags: + - CSS + - CSS Value + - inherit +translation_of: Web/CSS/inherit +--- +
 
+ +

{{CSSRef}}

+ +

 inherit 关键字使得元素获取其父元素的计算值。它可以应用于任何CSS属性,包括CSS简写 {{cssxref("all")}}。

+ +

对于继承属性,inherit 关键字只是增强了属性的默认行为,只有在重载(overload)其它规则的时候被使用。对于非继承属性,inherit 这指定的行为通常没有多大意义,一般使用使用 {{cssxref("initial")}} 或 {{cssxref("unset")}} 作为替代。

+ +

继承始终来自文档树中的父元素,即使父元素不是包含块。

+ +

示例

+ +
/* 设置二级标题的颜色为绿色 */
+h2 { color: green; }
+
+/* ...but leave those in the sidebar alone so they use their parent's color */
+#sidebar h2 { color: inherit; }
+
+ +

在下面这个例子中,如果sidebar 中h2元素的div匹配下面的规则的话,颜色会变成蓝色。

+ +
div#current { color: blue; }
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{ SpecName('CSS4 Cascade', '#inherit', 'inherit') }}{{Spec2('CSS4 Cascade')}}No changes from Level 3.
{{ SpecName('CSS3 Values', "#common-keywords", "inherit") }}{{ Spec2('CSS3 Values') }}No significant change from {{ SpecName('CSS2.1') }}.
{{ SpecName('CSS2.1', "cascade.html#value-def-inherit", "inherit") }}{{ Spec2('CSS2.1') }}Initial definition.
+ +

浏览器兼容性

+ +
+ + +

{{Compat("css.types.global_keywords.inherit")}}

+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf