问题描述
我认为 initial
值会恢复最初呈现的样式(由浏览器的内部用户代理样式表应用).
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="inline">
,而 div.initial
规则将使用 div
的 block
的原始显示值来显示 <div class="initial">
.
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
.
但是当我探索这个时,<div class="initial">
显示内联.我错了吗?谁能详细说明一下?
But when I explore this, <div class="initial">
displays inline. Am I wrong? Can anyone elaborate more on this?
推荐答案
initial
value(不是属性)表示属性的初始值,如 CSS 规范中所定义:'initial' 关键字表示指定为属性初始值的指定值."因此,它的含义取决于属性,而不取决于其他任何东西,例如不在浏览器或应用该属性的元素上.所以它不是意味着浏览器默认.
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.
例如对于display
属性,initial
always表示inline
,因为这是指定的初始值的财产.在示例中,浏览器默认是 block
,因为元素是 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
.
因此,initial
值的用处有限.由于误解,它的主要作用似乎是混淆了人们.一个可能的用例是 color
属性,因为它的初始值取决于浏览器(我们知道,大部分是黑色,但不一定).对于它,initial
表示浏览器默认值,因为属性就是这样定义的,一个类似的用例是 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中“初始"值的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!