freeCodeCamp/guide/chinese/css/properties/background-property/index.md

47 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Background Property
localeTitle: 背景资产
---
## 背景资产
CSS后台属性允许用一个简写声明1一次声明所有八个背景属性。
background属性指定为一个或多个背景图层以逗号分隔以获取以下属性2
* 背景颜色
* 背景图片
* 背景位置
* 背景大小
* 背景重复
* 背景起源
* 背景素材
* 背景附件
语法1
```css
body {
/* Using a <background-color> */
background: green;
}
.error {
/* Using a <bg-image> and <repeat-style> */
background: url("test.jpg") repeat-y;
}
header {
/* Using a <box> and <background-color> */
background: border-box red;
}
.topbanner {
/* A single image, centered and scaled */
background: no-repeat center/80% url("../img/image.png");
}
```
### 来源
1. [访问MDN的背景页面以获取更多信息。](https://developer.mozilla.org/en-US/docs/Web/CSS/background)
2. [访问W3School的CSS背景属性页面以获取更多信息。](https://www.w3schools.com/cssref/css3_pr_background.asp)