首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

inherit

inheritCSS关键字使得元素的指定属性值取其父元素的该属性的计算值。它可以应用于任何CSS属性,包括CSS简写属性all

对于继承的属性,这强化了默认行为,只需要覆盖另一个规则。对于非继承属性,这种指定行为通常就毫无意义,你可以考虑使用initial替代,或者在all属性中设置unset

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

实例

代码语言:javascript
复制
/* Make second-level headers green */
h2 { color: green; }

/* ...but leave those in the sidebar alone so they use their parent's color */
#sidebar h2 { color: inherit; }

在这个例子中边栏内的元素h2可能是不同的颜色。例如,如果其中之一是由规则匹配的div的孩子

代码语言:javascript
复制
div#current { color: blue; }

这将是蓝色的。

规范

Specification

Status

Comment

CSS Cascading and Inheritance Level 4The definition of 'inherit' in that specification.

Working Draft

No changes from Level 3.

CSS Values and Units Module Level 3The definition of 'inherit' in that specification.

Candidate Recommendation

No significant change from CSS Level 2 (Revision 1).

CSS Level 2 (Revision 1)The definition of 'inherit' in that specification.

Recommendation

Initial definition.

浏览器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari (WebKit)

Basic support

1.0

1.0 (1.7 or earlier)

8.0

4.0

1.0 (85)

Feature

Android

Firefox Mobile (Gecko)

IE Phone

Opera Mobile

Safari Mobile

Basic support

1.0

1.0 (1.0)

?

?

(Yes)

另见

  • Inheritance继承

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com