Style backgroundRepeat 屬性
- 上一頁 backgroundPosition
- 下一頁 backgroundClip
- 返回上一層 HTML DOM Style 對象
定義和用法
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 |
支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
- 上一頁 backgroundPosition
- 下一頁 backgroundClip
- 返回上一層 HTML DOM Style 對象