Style backgroundRepeat 属性
更多“自己尝试”的例子见下文。
描述
backgroundRepeat 属性设置或返回背景图像的重复(平铺)方式。
语法
返回 backgroundRepeat 属性
对象.style.backgroundRepeat
设置 backgroundRepeat 属性
对象.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
属性值
| 值 | 描述 |
|---|---|
| 重复 | 背景图像在垂直和水平方向都重复。这是默认值。 |
| repeat-x | 背景图像只在水平方向重复 |
| repeat-y | 背景图像只在垂直方向重复 |
| no-repeat | 背景图像不重复 |
| initial | 将此属性设置为其默认值。阅读关于 initial |
| inherit | 从其父元素继承此属性。阅读关于 inherit |
技术详情
| 默认值 | 重复 |
|---|---|
| 返回值 | 一个字符串,表示背景图像的重复方式。 |
| CSS 版本 | CSS1 |
浏览器支持
backgroundRepeat 是 CSS1 (1996) 的特性。
所有浏览器都完全支持。
| Chrome | Edge | Firefox | Safari | Opera | IE |
| 是 | 是 | 是 | 是 | 是 | 是 |
更多示例
示例
更改指定 DIV 元素的 backgroundRepeat 属性
document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
自己动手试一试 »
示例
将背景图像设置为水平或垂直重复
function repeatVer() {
document.body.style.backgroundRepeat = "repeat-y";
}
function repeatHor() {
document.body.style.backgroundRepeat = "repeat-x";
}
自己动手试一试 »