什么是使用CSS中的“初始”的价值? [英] What is use of 'initial' value in CSS?
问题描述
我认为初始
值将恢复最初呈现样式(如应用通过的的浏览器的内部的用户代理的样式表)。
I thought that the initial
value would restore initially rendered styles (as applied by a browser's internal user-agent stylesheet).
例如:
div.inline {
display: inline;
}
div.initial {
display: initial;
}
我所期望的 div.inline
规则将显示< DIV CLASS =内联>
内联使用 A <$;模式, div.initial
规则将显示&LT; DIV CLASS =初始&GT C $ C> DIV
中的原始的显示值块
。
I expected the div.inline
rule would display <div class="inline">
in inline mode, and the div.initial
rule would display <div class="initial">
using a div
's original display value of block
.
但是,当我探讨这个,&LT; DIV CLASS =初始&GT;内联
显示。我错了吗?任何人都可以更多地讨论这个?
But when I explore this, <div class="initial">
displays inline. Am I wrong? Can anyone elaborate more on this?
推荐答案
初始
价值(不属性)表示属性的初始值,如CSS规范定义的:被指定为初始的关键字重新presents规定值该属性的初始值,因此,它的含义取决于财产,但没有任何其他问题,例如:不上的浏览器或该属性被施加到元件上。所以它的不的意思是浏览器的默认。
The initial
value (not attribute) denotes the initial value of the property, as defined in CSS specifications: "The ‘initial’ keyword represents the specified value that is designated as the property's initial value." Thus, its meaning depends on the property, but not on anything else, e.g. not on the browser or on the element that the property is being applied to. So it does not mean browser default.
例如,对于显示
属性,初始
的总是的手段在线
,因为这是物业指定的初始值。在这个例子中的情况下,的浏览器的默认的是块
,因为该元素是 DIV
。
For example, for the display
property, initial
always means inline
, because that’s the designated initial value of the property. In the example case, the browser default is block
, since the element is div
.
因此,初始
价值是有限的用处。它的主要作用似乎是蛊惑人心,因误解。一个可能的用例是颜色
属性,因为它的初始值是依赖于浏览器(主要是黑人,因为我们知道,但不一定)。对于它,初始
意味着浏览器的默认,因为这是如何的财产已经被定义,类似的用例是 FONT-FAMILY
:通过声明 FONT-FAMILY:初始
,你的浏览器的默认字体(这可能依赖于浏览器的设置)
Thus, the initial
value is of limited usefulness. Its main effect seems to be to confuse people, due to misunderstandings. A possible use case is for the color
property, since its initial value is browser-dependent (mostly black, as we know, but not necessarily). For it, initial
means browser default, since that’s how the property has been defined, A similar use case is for font-family
: by declaring font-family: initial
, you get browser’s default font (which may depend on browser settings).
的用处是进一步缺乏对IE浏览器(IE,甚至10)的支持有限。
The usefulness is further limited by lack of support on IE (even IE 10).
这篇关于什么是使用CSS中的“初始”的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!