# Multiple backgrounds
**版本:CSS3**
继承性:无
### 语法:
**background** : [background-image] | [background-origin] | [background-clip] | [background-repeat] | [background-size] | [background-position]
**相关属性**: background-image | [background-origin](#) | [background-clip](#) | background-repeat | [background-size](#) | background-position
### 取值:
*<background-image>*:指定或检索对象的背景图像。*<background-origin>*:指定背景的显示区域。参见[background-origin](#)*<background-clip>*:指定背景的裁剪区域。参见[background-clip](#)*<background-repeat>*:设置或检索对象的背景图像是否及如何重复铺排。*<background-size>*:指定背景图片的大小。参见[background-size](#)*<background-position>*:设置或检索对象的背景图像位置。
### 说明:
多重背景图象,可以把不同背景图象只放到一个块元素里。
多个图片url之间使用逗号隔开即可;如果有多个背景图片,而其他属性只有一个(例如background-repeat只有一个),表明所有背景图片应用该属性值。
CSS3中在容器的多层背景,各子属性与逗号来分隔值,如果指定的值,如下:
> background-image: w1, w2, w3,…, wM
background-repeat: x1, x2, x3,…, xR
background-size: y1, y2, y3,…, yS
background-position: s1, s2, s3,…, sP
当背景层的数值是N = max(M,R, S, P)
每个属性可以假如它的值为n,通过重复指定的值如下所示:
> background-image:
w1
> ,…
wM
> ,
w1
> ,…
wM
> ,
w1
> ,… /*
N
> values */
> background-repeat:
x1
> ,…
xR
> ,
x1
> ,…
xR
> ,
x1
> ,… /*
N
> values */
> background-size:
y1
> ,…
yS
> ,
y1
> ,…
yS
> ,
y1
> ,… /*
N
> values */
> background-position:
s1
> ,…
rP
> ,
s1
> ,…
rP
> ,
s1
> ,… /*
N
> values */
范例书写:
> background-image: url(img/multiple-backgrounds.png), url(img/multiple-backgrounds.png), url(img/multiple-backgrounds.png);
background-position: left top, -320px bottom, -640px top;
background-repeat: no-repeat, no-repeat, repeat-y;
也可以简写:
> background: url(img/multiple-backgrounds.png) left top no-repeat, url(img/multiple-backgrounds.png) -320px bottom no-repeat, url(img/multiple-backgrounds.png) -640px top repeat-y;
### 兼容性:
<table><thead><tr><th class="type">类型</th> <th class="type_ie"><img src="https://box.kancloud.cn/2015-09-02_55e5d385322ef.png" alt="IE" />Internet Explorer</th> <th class="type_firefox"><img src="https://box.kancloud.cn/2015-09-02_55e5d385398e4.png" alt="Firefox" />Firefox</th> <th class="type_chrome"><img src="https://box.kancloud.cn/2015-09-02_55e5d38541e4c.png" alt="Chrome" />Chrome</th> <th class="type_opera"><img src="https://box.kancloud.cn/2015-09-02_55e5d385491d2.png" alt="Opera" />Opera</th> <th class="type_safari"><img src="https://box.kancloud.cn/2015-09-02_55e5d38552849.png" alt="Safari" />Safari</th> </tr></thead><tbody><tr><td rowspan="4" class="version">版本</td> <td class="support no"><span>(×)</span>IE6</td> <td class="support no"><span>(×)</span>Firefox 2.0</td> <td class="support yes"><span>(√)</span>Chrome 1.0.x</td> <td class="support no"><span>(×)</span>Opera 9.63</td> <td class="support yes"><span>(√)</span>Safari 3.1</td> </tr><tr><td class="support no"><span>(×)</span>IE7</td> <td class="support no"><span>(×)</span>Firefox 3.0</td> <td class="support yes"><span>(√)</span>Chrome 2.0.x</td> <td></td> <td class="support yes"><span>(√)</span>Safari 4</td> </tr><tr><td class="support no"><span>(×)</span>IE8</td> <td class="support no"><span>(×)</span>Firefox 3.5</td> <td></td> <td></td> <td></td> </tr><tr><td></td> <td></td> <td></td> <td></td> <td></td> </tr></tbody></table>
### 示例:
![multiple-backgrounds](https://box.kancloud.cn/2015-09-02_55e5d3855b228.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="utf-8" /><meta name="robots" content="all" /><meta name="author" content="Tencent-ISRD" /><meta name="Copyright" content="Tencent" /><title>Border-radius</title></head><body><div style="background-image: url(img/multiple-backgrounds.png), url(img/multiple-backgrounds.png), url(img/multiple-backgrounds.png); background-position: left top, -320px bottom, -640px top;background-repeat: no-repeat, no-repeat, repeat-y;width:260px;padding:20px;"> <p>这是一个宽为300px,高度自适应的多背景示范容器,完成的一个九宫格模型</p> </div></body></html>
复制代码
Copyright © 2009 [Tencent ISD webteam](http://webteam.tencent.com/). All Rights Reserved
### 快速跳转
- [语法](# "跳转到“语法”")
- [取值](# "跳转到“取值”")
- [说明](# "跳转到“说明”")
- [兼容性](# "跳转到“兼容性”")
- [示例](# "跳转到“示例”")
- CSS3 Properties
- 边框(Border)
- Border-color
- Border-image
- Border-radius
- box-shadow
- 背景(Background)
- background-origin
- background-clip
- Background-size
- Multiple backgrounds
- 颜色(Color)
- HSL colors
- HSLA colors
- opacity
- RGBA colors
- 文本(Text effects)
- text-shadow
- text-overflow
- word-wrap
- 用户界面(User-interface)
- box-sizing
- resize
- outline
- outline-width
- outline-style
- outline-offset
- outline-color
- nav-index
- nav-up
- nav-right
- nav-down
- nav-left
- 基础盒模型(Basic box model)
- overflow
- overflow-x
- overflow-y
- 内容(Generated Content)
- content
- 其它模块(Other modules)
- media queries
- Speech
- columns
- column-width
- column-span
- column-rule
- column-rule-color
- column-rule-width
- column-rule-style
- column-gap
- column-fill
- column-count
- column-break-before
- column-break-after
- @font-face
- 选择器(selectors)
- 子串匹配的属性选择符 E[att^="val"]
- 子串匹配的属性选择符 E[att$="val"]
- 子串匹配的属性选择符 E[att*="val"]
- 结构性伪类 E:root
- 结构性伪类 E:nth-child(n)
- 结构性伪类 E:nth-last-child(n)
- 结构性伪类 E:nth-of-type(n)
- 结构性伪类 E:nth-last-of-type(n)
- 结构性伪类 E:last-child
- 结构性伪类 E:first-of-type
- 结构性伪类 E:only-child
- 结构性伪类 E:only-of-type
- 结构性伪类 E:empty
- UI元素状态伪类 E:checked
- UI元素状态伪类 E:enabled
- UI元素状态伪类 E:disabled
- UI元素状态伪类 E::selection
- 否定伪类 E:not(s)
- 目标伪类 E:target
- 通用兄弟元素选择器 E ~ F