Does this shorthand for background removes the oth

2019-08-10 03:09发布

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条回答
可以哭但决不认输i
2楼-- · 2019-08-10 03:41

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.

查看更多
登录 后发表回答