background - color:没有有效的CSS吗?

时间:2022-11-12 11:11:12

Can anyone tell me if the following CSS is valid?

谁能告诉我以下CSS是否有效?

.class {
    background-color:none;
}

5 个解决方案

#1


377  

You probably want transparent as none is not a valid background-color value.

您可能想要透明,因为没有一个不是有效的背景颜色值。

The CSS 2.1 spec states the following for the background-color property:

CSS 2.1规范描述了背景色属性:

Value: <color> | transparent | inherit

值: |透明|继承。

<color> can be either a keyword or a numerical representation of a colour. Valid color keywords are:

可以是一个关键字,也可以是一个颜色的数字表示。有效的关键词是:颜色

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow

aqua,黑色,蓝色,紫红色,灰色,绿色,石灰,栗色,海军蓝,橄榄色,橙色,紫色,红色,银色,茶色,白色和黄色。

transparent and inherit are valid keywords in their own right, but none is not.

透明和继承本身是有效的关键字,但没有一个是无效的。

#2


138  

No, use transparent instead none . See working example here in this example if you will change transparent to none it will not work

不,用透明的代替没有。在本例中,如果您将透明更改为none,请参见这里的工作示例。

use like .class { background-color:transparent; }

使用like .class {backbasecolor:transparent;}


Where .class is what you will name your transparent class.

#3


48  

The answer is no.

答案是否定的。

Incorrect

.class {
    background-color: none; /* do not do this */
}

Correct

.class {
    background-color: transparent;
}

background-color: transparent accomplishes the same thing what you wanted to do with background-color: none.

背景色:透明完成同样的事情,你想用背景色做什么:没有。

#4


5  

.class {
    background-color:none;
}

This is not a valid property. W3C validator will display following error:

这不是一个有效的属性。W3C验证器将显示以下错误:

Value Error : background-color none is not a background-color value : none

值错误:背景色没有一个不是背景色值:没有。

transparent may have been selected as better term instead of 0 or none values during the development of specification of CSS.

在CSS规范的开发过程中,透明可能被选为更好的术语,而不是0或没有任何值。

#5


4  

CSS Level 3 specifies the unset property value. From MDN:

CSS Level 3指定未设置的属性值。中数:

The unset CSS keyword is the combination of the initial and inherit keywords. Like these two other CSS-wide keywords, it can be applied to any CSS property, including the CSS shorthand all. This keyword resets the property to its inherited value if it inherits from its parent or to its initial value if not. In other words, it behaves like the inherit keyword in the first case and like the initial keyword in the second case.

unset CSS关键字是初始和继承关键字的组合。与这两个CSS范围内的关键字一样,它可以应用于任何CSS属性,包括CSS的所有缩写。该关键字将属性重置为其继承的值,如果它继承父或其初始值(如果没有)。换句话说,它的行为就像第一个例子中的继承关键字,就像第二个例子中的初始关键字。

Unfortunately this value is currently not supported in all browsers, including IE, Safari and Opera. I suggest using transparent for the time being.

不幸的是,该值目前在所有浏览器中都不受支持,包括IE、Safari和Opera。我建议暂时使用透明。

#1


377  

You probably want transparent as none is not a valid background-color value.

您可能想要透明,因为没有一个不是有效的背景颜色值。

The CSS 2.1 spec states the following for the background-color property:

CSS 2.1规范描述了背景色属性:

Value: <color> | transparent | inherit

值: |透明|继承。

<color> can be either a keyword or a numerical representation of a colour. Valid color keywords are:

可以是一个关键字,也可以是一个颜色的数字表示。有效的关键词是:颜色

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow

aqua,黑色,蓝色,紫红色,灰色,绿色,石灰,栗色,海军蓝,橄榄色,橙色,紫色,红色,银色,茶色,白色和黄色。

transparent and inherit are valid keywords in their own right, but none is not.

透明和继承本身是有效的关键字,但没有一个是无效的。

#2


138  

No, use transparent instead none . See working example here in this example if you will change transparent to none it will not work

不,用透明的代替没有。在本例中,如果您将透明更改为none,请参见这里的工作示例。

use like .class { background-color:transparent; }

使用like .class {backbasecolor:transparent;}


Where .class is what you will name your transparent class.

#3


48  

The answer is no.

答案是否定的。

Incorrect

.class {
    background-color: none; /* do not do this */
}

Correct

.class {
    background-color: transparent;
}

background-color: transparent accomplishes the same thing what you wanted to do with background-color: none.

背景色:透明完成同样的事情,你想用背景色做什么:没有。

#4


5  

.class {
    background-color:none;
}

This is not a valid property. W3C validator will display following error:

这不是一个有效的属性。W3C验证器将显示以下错误:

Value Error : background-color none is not a background-color value : none

值错误:背景色没有一个不是背景色值:没有。

transparent may have been selected as better term instead of 0 or none values during the development of specification of CSS.

在CSS规范的开发过程中,透明可能被选为更好的术语,而不是0或没有任何值。

#5


4  

CSS Level 3 specifies the unset property value. From MDN:

CSS Level 3指定未设置的属性值。中数:

The unset CSS keyword is the combination of the initial and inherit keywords. Like these two other CSS-wide keywords, it can be applied to any CSS property, including the CSS shorthand all. This keyword resets the property to its inherited value if it inherits from its parent or to its initial value if not. In other words, it behaves like the inherit keyword in the first case and like the initial keyword in the second case.

unset CSS关键字是初始和继承关键字的组合。与这两个CSS范围内的关键字一样,它可以应用于任何CSS属性,包括CSS的所有缩写。该关键字将属性重置为其继承的值,如果它继承父或其初始值(如果没有)。换句话说,它的行为就像第一个例子中的继承关键字,就像第二个例子中的初始关键字。

Unfortunately this value is currently not supported in all browsers, including IE, Safari and Opera. I suggest using transparent for the time being.

不幸的是,该值目前在所有浏览器中都不受支持,包括IE、Safari和Opera。我建议暂时使用透明。