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";
}
自己動手試一試 »