CSS中的继承是什么意思? [英] What does inherit mean in CSS?

查看:42
本文介绍了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:

jsFiddle

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆