<分区>
我经常使用background: inherit;
。像这样,许多其他 CSS 属性接受继承作为值。
但是 inherit
是什么意思呢?它是如何工作的?
标签 css
<分区>
我经常使用background: inherit;
。像这样,许多其他 CSS 属性接受继承作为值。
但是 inherit
是什么意思呢?它是如何工作的?
最佳答案
inherit
意味着样式将从元素的父元素继承。例如:
HTML
<div class="blue">
<div class="inherit">I also have a blue background!</div>
</div>
CSS
.blue { background: blue; }
.inherit { background: inherit; }
在 background
上使用 inherit
通常不会有太大好处,并且通常会产生与默认透明背景相同的结果。上面的示例实际上没有添加任何东西,它在蓝色背景之上放置了一个蓝色背景,inherit
的主要目的是用于某些默认值,例如 color
和 字体大小
。
关于css - 继承在CSS中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15564650/