下面有更多 "亲自试一试" 示例。
backgroundRepeat 属性设置或返回如何重复(平铺)背景图片。
返回backgroundRepeat属性:
object.style.backgroundRepeat
设置backgroundRepeat属性:
object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
Value | Description |
---|---|
repeat | The background image is repeated both vertically and horizontally. This is default |
repeat-x | The background image is only repeated horizontally |
repeat-y | The background image is only repeated vertically |
no-repeat | The background-image is not repeated |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
默认值: | 重复 |
---|---|
返回值: | 一个字符串,表示背景图片如何重复 |
CSS版本 | CSS1 |
backgroundRepeat
是 CSS1 (1996) 的一项功能。
所有浏览器都完全支持它:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
更改指定 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";
}
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!