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不重复背景图像。
inheritbackground-repeat 属性的设置从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


实例

实例

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本站教程(icodebang.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 对象参考手册 Style 对象

0 个评论

要回复文章请先登录注册