您可以用背景的简写形式声明背景大小吗:

fau*_*ism 3 css

我习惯于像这样用速记写出我的背景属性......

background: #444 url(hero.jpg) no-repeat center right;
Run Code Online (Sandbox Code Playgroud)

无论如何,我可以将背景大小属性合并到我的速记中吗?一些新的 css3 背景属性怎么样?可以用速记来写吗?

ama*_*ert 8

是的。完整的 CSS3 语法是:

background: color position/size repeat origin clip attachment image|initial|inherit;
Run Code Online (Sandbox Code Playgroud)

注意:如果简写声明中的属性之一是background-size属性,则必须使用/(斜杠)将其与background-postion属性分隔开,例如background:url(smiley.gif) 10px 20px/50px 50px ; 将生成一个背景图像,距左侧 10 像素,距顶部 20 像素,图像的大小将为 50 像素宽和 50 像素高。