Background Check: Use background-color to set the background color

Don’t simply use the shorthand if you want to set only the background color:

[code lang=”css” title=”CSS”]
div {background:red;}
[/code]

Because what that really means is:
[code lang=”css” title=”CSS”]
div {background:none repeat scroll 0 0 red;}
[/code]

The background values in order are:

  • background-image
  • background-repeat
  • background-attachment
  • background-position
  • background-color

One of the conflicts in using the shorthand in styling only the background color is that it sets the background-image to none.

In case that you need to style the same selector with a background image, the value in the shorthand property will persist.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *