CSS中的继承是什么意思? [英] What does inherit mean in CSS?
问题描述
我经常使用 background:Inherit;
.像这样,许多其他CSS属性都将继承作为值接受.
I often use background: inherit;
. Like this, many other CSS properties accept inherit as a value.
但是继承
是什么意思?如何运作?
But what does inherit
mean? How does it work?
推荐答案
继承
意味着该样式将从元素的父级继承.例如:
inherit
means simply that the style will be inherited from the element's parent. For example:
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
和 font-size
.
Using inherit
on background
will normally not do you much good however, and normally produce the same as the default of a transparent background would. The above example adds nothing really, it puts a blue background on top of a blue background, the main purpose of inherit
is for use in certain default values like with color
and font-size
.
这篇关于CSS中的继承是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!