Does this shorthand for background removes the other attributes?

ε祈祈猫儿з 提交于 2019-12-24 10:16:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!