问题
If I have:
background:#A2A2A2 url('./images/img.png') repeat-x left bottom;
and then I use:
background:#000000; /* not to confuse with 'background-color' */
Do background-image
,background-repeat
and background-position
are lost?
回答1:
background-image
, background-repeat
and background-position
(among other things) will be implicitly set to their default values when you leave them out in the shorthand property. It's just how a shorthand property works (for the most part).
The computed background styles end up looking something like this:
background-color: #000000; /* Your specified value */
background-image: none; /* Default value */
background-repeat: repeat; /* Default value */
background-position: 0% 0%; /* Default value */
So yes, those values you set in the first shorthand declaration will be lost.
来源:https://stackoverflow.com/questions/8686656/does-this-shorthand-for-background-removes-the-other-attributes