Style backgroundRepeat 属性
定义和用法
backgroundRepeat 属性设置或返回如何重复(平铺)背景图像。
另请参阅:
HTML 样式:background 属性
CSS 教程:CSS 背景
CSS3 教程:CSS3 背景
CSS 参考手册:background-repeat 属性
实例
例子 1
将背景图像设置为不重复(no-repeat):
document.body.style.backgroundRepeat = "repeat-y";
例子 2
更改指定 DIV 元素的 backgroundRepeat 属性:
document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
例子 3
将背景图像设置为水平或垂直重复:
function repeatVer() {
document.body.style.backgroundRepeat = "repeat-y";
}
function repeatHor() {
document.body.style.backgroundRepeat = "repeat-x";
}
例子 4
返回文档的 background-repeat 值:
alert(document.body.style.backgroundRepeat);
语法
返回 backgroundRepeat 属性:
object.style.backgroundRepeat
设置 backgroundRepeat 属性:
object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
属性值
| 值 | 描述 |
|---|---|
| repeat | 背景图像垂直和水平重复。默认。 |
| repeat-x | 背景图像仅水平重复。 |
| repeat-y | 背景图像仅垂直重复。 |
| no-repeat | 背景图像不重复。 |
| initial | 将此属性设置为其默认值。请参阅 initial。 |
| inherit | 从其父元素继承此属性。请参阅 inherit。 |
技术细节
| 默认值: | repeat |
|---|---|
| 返回值: | 字符串,表示背景图像如何重复。 |
| CSS 版本: | CSS1 |
浏览器支持
backgroundRepeat 是 CSS1 (1996) 特性。
所有浏览器都完全支持它:
| Chrome | Edge | Firefox | Safari | Opera | IE |
|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Opera | IE |
| 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |