# 背景属性

URL: https://caijiao.org/css/04-color-background/02-background-properties
Source: docs/css/04-color-background/02-background-properties.md
Description: 背景属性用于设置元素的背景颜色、图片及其位置、大小和重复方式，是网页设计中常用的样式控制。

CSS 的背景属性用于控制元素的背景表现，包括颜色、图片、位置、大小和是否重复等。

## 1. 背景颜色（background-color）

设置元素背景颜色：

```css
background-color: #f0f0f0;
```

## 2. 背景图片（background-image）

为元素设置背景图片：

```css
background-image: url("bg.jpg");
```

## 3. 背景位置（background-position）

控制背景图片的位置：

```css
background-position: center;
background-position: 10px 20px;
```

## 4. 背景大小（background-size）

控制背景图片的大小：

```css
background-size: cover; /* 充满容器 */
background-size: contain; /* 保持比例完整显示 */
background-size: 100px 50px; /* 指定宽高 */
```

## 5. 背景重复（background-repeat）

控制背景图片是否重复：

```css
background-repeat: no-repeat;
background-repeat: repeat-x;
background-repeat: repeat-y;
background-repeat: repeat;
```

## 背景属性示例

[在线代码演示](/css/demos/4.html)
