What's the difference between specifying a background color using background
and background-color
?
Snippet #1
body { background-color: blue; }
Snippet #2
body { background: blue; }
What's the difference between specifying a background color using background
and background-color
?
Snippet #1
body { background-color: blue; }
Snippet #2
body { background: blue; }
I've noticed when generating emails for Outlook...
background
is the shortcut forbackground-color
and few other background related stuffs as below:Read the statement below from W3C:
When using the shorthand property the order of the property values is:
One thing I've noticed that I don't see in the documentation is using
background: url("image.png")
short hand like above if the image is not found it sends a 302 code instead of being ignored like it is if you use
There is no difference. Both will work in the same way.
Background property includes all of this properties and you can just write them in one line.
Premising that those are two distinct properties, in your specific example there's no difference in the result, since
background
actually is a shorthand forThus, besides the
background-color
, using thebackground
shortcut you could also add one or more values without repeating any otherbackground-*
property more than once.Which one to choose is essentially up to you, but it could also depend on specific conditions of your style declarations (e.g if you need to override just the
background-color
when inheriting other relatedbackground-*
properties from a parent element, or if you need to remove all the values except thebackground-color
).background
will supercede all previousbackground-color
,background-image
, etc. specifications. It's basically a shorthand, but a reset as well.I will sometimes use it to overwrite previous
background
specifications in template customizations, where I would want the following:background: white url(images/image1.jpg) top left repeat;
to be the following:
background: black;
So, all parameters (
background-image
,background-position
,background-repeat
) will reset to their default values.