inherit
inherit CSS 关键字使元素从其父元素获取属性的计算值。它可以应用于任何 CSS 属性,包括 CSS 简写属性 all。
对于继承属性,这强化了默认行为,并且仅在需要覆盖其他规则时才需要。
注意: 继承总是来自文档树中的父元素,即使父元素不是包含块。
示例
从规则中排除选定的元素
css
/* Make second-level headers green */
h2 {
color: green;
}
/* Leave those in the sidebar alone so they use their parent's color */
#sidebar h2 {
color: inherit;
}
在此示例中,侧边栏中的 h2 元素可能具有不同的颜色。例如,考虑其中一个将是符合规则的 div 的子元素
css
div#current {
color: blue;
}
然后,它将是蓝色的。
规范
| 规范 |
|---|
| CSS 层叠与继承第四级 # inherit |
浏览器兼容性
加载中…