Is background-color:none valid CSS?

前端 未结 7 2296
独厮守ぢ
独厮守ぢ 2020-11-28 19:04

Can anyone tell me if the following CSS is valid?

.class {
    background-color:none;
}
相关标签:
7条回答
  • 2020-11-28 19:35
    .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.

    0 讨论(0)
  • 2020-11-28 19:36

    write this:

    .class {
    background-color:transparent;
    }
    
    0 讨论(0)
  • 2020-11-28 19:41

    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.

    0 讨论(0)
  • 2020-11-28 19:41

    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.

    0 讨论(0)
  • 2020-11-28 19:51

    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.

    0 讨论(0)
  • 2020-11-28 19:54

    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:

    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

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

    0 讨论(0)
提交回复
热议问题