Style backgroundRepeatProperty

Style 对象参考手册Style Object

Definition and Usage

The backgroundRepeat property sets or returns how a background image is repeated.

Syntax

Set the backgroundRepeat property:

Object.style.backgroundRepeat="repeat|repeat-x|repeat-y|no-repeat|inherit"

Return the backgroundRepeat property:

Object.style.backgroundRepeat

Value Description
repeat Default. Repeats the background image vertically and horizontally.
repeat-x Repeats the background image horizontally.
repeat-y Repeats the background image vertically.
no-repeat Does not repeat the background image.
inherit The setting of the background-repeat property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the backgroundRepeat property.

Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Set the background image to repeat vertically:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.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()">Vertically repeat background image</button>
<br>
<h1>Hello World!</h1>
<p>This is a paragraph</p>
    
</body>
</html>

Try it Yourself »


Style 对象参考手册Style Object Other Extensions