天天看点

Style backgroundRepeat 属性

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

浏览器支持

Style backgroundRepeat 属性
Style backgroundRepeat 属性
Style backgroundRepeat 属性
Style backgroundRepeat 属性
Style backgroundRepeat 属性

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

注意:

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

实例

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

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>菜鸟教程(runoob.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 对象