Is background-color:none valid CSS?

2020-01-25 13:04发布

Can anyone tell me if the following CSS is valid?

.class {
    background-color:none;
}

7条回答
孤傲高冷的网名
2楼-- · 2020-01-25 13:13
.class {
    background-color:none;
}

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

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.

查看更多
一夜七次
3楼-- · 2020-01-25 13:16

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楼-- · 2020-01-25 13:31

write this:

.class {
background-color:transparent;
}
查看更多
趁早两清
5楼-- · 2020-01-25 13:32

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

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.

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

查看更多
6楼-- · 2020-01-25 13:36

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

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


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

查看更多
smile是对你的礼貌
7楼-- · 2020-01-25 13:38

So, I would like to explain the scenario where I had to make use of this solution. Basically, I wanted to undo the background-color attribute set by another CSS. The expected end result was to make it look as though the original CSS had never applied the background-color attribute . Setting background-color:transparent; made that effective.

查看更多
登录 后发表回答