Style backgroundRepeat 属性

Style 对象参考手册 Style 对象

定义和用法

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 属性的设置从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 backgroundRepeat 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


实例

实例

设置背景图像为垂直方向重复:

<html>
<head>
<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()">Repeat vertically</button>
<br>

<h1>Hello World!</h1>
<p>This is a paragraph</p>

</body>
</html>

尝试一下 »


Style 对象参考手册 Style 对象