Today when I tried something with background option, I tried to put value none and then validated it and didn't receive error. How come?
In official specifications as I understod property background can't have value none or can it?

1 answer

4
points

The 'background' property is a shorthand property for setting the individual background properties (i.e., 'background-color', 'background-image', 'background-repeat', 'background-attachment' and 'background-position') at the same place in the style sheet.

Given a valid declaration, the 'background' property first sets all the individual background properties to their initial values, then assigns explicit values given in the declaration.

background-image: none; is a valid declaration and so is seen as setting just the image to none when used in the shorthand background

i.e

background: none;

means a value for 'background-image' has been given and the other individual properties are set to their initial value.

Answered over 6 years ago by Tony Crockford
  • Great. Now now I understand that. Thank you. Eugene over 6 years ago
  • Did I understand correctly, that specifying `backgroud: url('some_image.jpg');` will be equal to `background-image: url('some_image.jpg');` ? Eugene over 6 years ago
  • Not exactly. "background-image" only sets the background image and does not touch any other CSS properties. "background" resets ALL background properties as Tony described. So if you set background-color, background-position, background-repeat, etc. earlier in your CSS, they will all be overridden if you use "background" but retained if you use "background-image". Doug over 6 years ago
  • Ou. Ok. Great. Now I have the full understanding. Thank you. Eugene over 6 years ago