像background这样的CSS缩写是否与价值差距有关?我用背景试了一下。我想动态地设置一些背景值静态和backgorund图像。
background
我做了以下事情:
background: no-repeat contain center;
应该动态地添加background-image。我错了吗?像我使用的速记不起作用。我是否必须使用单一属性(background-repeat, background-size, background-position ...)来实现这一点?
background-image
background-repeat, background-size, background-position
问题不在于缺少背景图像。问题在于背景大小和背景位置值。与其他长官不同,这两者的值具有非常特殊的语法:背景位置后跟/,后跟背景大小。见spec。
/
它应该是这样的:
background: no-repeat center / contain;
您始终可以单独设置背景图像。
其他一些短线确实有强制值。例如,font需要font-size和font-family。 background没有任何强制性价值观。
font