HTML DOM Style backgroundRepeat 屬性
定義和用法
backgroundRepeat 屬性設置或返回如何重複背景圖像。
語法
設置backgroundRepeat 屬性:
Object.style.backgroundRepeat="repeat|repeat-x|repeat-y|no-repeat|inherit"
返回backgroundRepeat 屬性:
Object.style.backgroundRepeat
值 | 描述 |
---|---|
repeat | 默认。垂直和水平方向重复背景图像。 |
repeat-x | 水平方向重复背景图像。 |
repeat-y | 垂直方向重复背景图像。 |
no-repeat | 不重复背景图像。 |
inherit | background-repeat 属性的设置从父元素继承。 |
瀏覽器支持
所有主要瀏覽器都支持backgroundRepeat 屬性。
注意: IE7及更早的版本不支持"inherit"值。IE8 只有規定了!DOCTYPE 才支持"inherit"。 IE9 支持"inherit"。
實例
實例
設置背景圖像為垂直方向重複:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
body{
background:#f3f3f3 url('img_tree.png');
}
</style>
<script>
function displayResult(){
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">垂直重複背景圖像</button>
<br>
<h1>Hello World!</h1>
<p>這是一個段落</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<style type="text/css">
body{
background:#f3f3f3 url('img_tree.png');
}
</style>
<script>
function displayResult(){
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">垂直重複背景圖像</button>
<br>
<h1>Hello World!</h1>
<p>這是一個段落</p>
</body>
</html>
嘗試一下»
Style對象