为了缩短代码,还可以在一个属性中指定所有背景属性。这称为简写属性。
而不是写:
body {
background-color: #ffffff;
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
您可以使用简写属性background
:
使用简写属性在一个声明中设置背景属性:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
亲自试一试 »
使用简写属性时,属性值的顺序为:
background-color
background-image
background-repeat
background-attachment
background-position
只要其他属性值按此顺序排列,即使缺少其中一个属性值也没关系。请注意,我们在上面的示例中没有使用 background-attachment 属性,因为它没有值。
Property | Description |
---|---|
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-clip | Specifies the painting area of the background |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-origin | Specifies where the background image(s) is/are positioned |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
background-size | Specifies the size of the background image(s) |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!