这篇翻译不完整。请帮忙从英语翻译这篇文章

 

 

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

对于继承属性,inherit 关键字只是增强了属性的默认行为,只有在重载(overload)其它规则的时候被使用。对于非继承属性,inherit 这指定的行为通常没有多大意义,一般使用使用“initial”或“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; }

 

Specifications

Specification Status Comment
CSS Cascading and Inheritance Level 4
inherit
Candidate Recommendation No changes from Level 3.
CSS Values and Units Module Level 3
inherit
Candidate Recommendation No significant change from CSS Level 2 (Revision 1).
CSS Level 2 (Revision 1)
inherit
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 8Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support YesEdge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

See also

  • Inheritance
  • Use initial to set a property to its initial value.
  • Use unset to set a property to its inherited value if it inherits, or to its initial value if not.
  • Use revert to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist).
  • The all property lets you reset all properties to their initial, inherited, reverted, or unset state at once.

文档标签和贡献者

此页面的贡献者: kongdanchen
最后编辑者: kongdanchen,