CSS Property: background-repeat
[this page | pdf | back links]
The CSS (CSS1) background-repeat property sets
whether/how a background image will be repeated. By default, a background-image
is placed at the top-left corner of an element and is repeated both vertically
and horizontally.
Valid property values
(other than inherit
and initial) are:
Value
|
Description
|
no-repeat
|
Not repeated
|
repeat
|
(default value).
Repeated both vertically and horizontally
|
repeat-x
|
Repeated only
horizontally
|
repeat-y
|
Repeated only vertically
|
Default Value:
|
repeat
|
JavaScript syntax:
|
e.g. object.style.backgroundRepeat="repeat-x"
|
Inherited:
|
No
|
Animatable:
|
No
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 200px; background-image: url(NematrianLogo.png); padding: 20px;}
p.x1 {background-repeat: repeat-x;}
</style>
</head>
<body>
1. Element with default property<br>
<p>1</p><br>
2. Element set using in-file HTML style
<p class="x1">2</p><br>
3. Element set using JavaScript
<p id="x2">3</p>
<script>
document.getElementById("x2").style.backgroundRepeat =
"repeat-x";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBackgroundRepeat() {
var x = document.createElement("DIV"); x.style.backgroundRepeat = "repeat-x"; return (window.getComputedStyle(x, null).backgroundRepeat == "repeat-x");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties