backgroundRepeat style property
Specifies or returns how to tile the backgroundImage relative to the upper-left corner of the container object.
With this property you have control over how the image is repeated (repeats vertically, horizontally, in both or in neither direction).
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: background-repeat |
Possible values:
The type of this property is string.
One of the following values:
Takes the value of this property from the computed style of the parent element. | |||||||
Image is not repeated. | |||||||
Default. Image is repeated both horizontally and vertically. | |||||||
Image is only repeated horizontally. | |||||||
Image is only repeated vertically. |
Default: repeat.
Example HTML code 1:
This example illustrates the use of the background-repeat property:
|
||||
<head> <style> .example { background-image: url("picture.gif"); background-repeat: repeat; width: 200px; height: 200px; } </style> </head> <body> <div class="example"> The background image, <br /> behind this element <br /> is repeated vertically <br /> and horizontally, too. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates all available repetitions of the background image in action:
|
||||
<head> <style> .example { background-image: url("picture.gif"); background-repeat: repeat; width: 200px; height: 120px; border:1px solid #CCCCCC; } .norepeat { background-repeat: no-repeat; } .repeatX { background-repeat: repeat-x; } .repeatY { background-repeat: repeat-y; } </style> </head> <body> <div class="example norepeat"> The background image <br /> behind this element <br /> is not repeated <br /> in any direction. </div> <br /> <div class="example repeatX"> The background image <br /> behind this element <br /> is repeated only <br /> in horizontal direction. </div> <br /> <div class="example repeatY"> The background image <br /> behind this element <br /> is repeated only <br /> in vertical direction. </div> <br /> <div class="example"> The background image <br /> behind this element <br /> is repeated in both <br /> directions. </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example illustrates the use of the backgroundRepeat property in JavaScript:
|
||||
<head> <style> .example { background-image: url("picture.gif"); background-repeat: repeat; } </style> <script type="text/javascript"> function ChangeRepeat (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the text of the selected option var selectState = selectTag.options[whichSelected].text; var div = document.getElementById ("myDiv"); div.style.backgroundRepeat = selectState; } </script> </head> <body> <div class="example" id="myDiv"> Change the repeat mode <br /> of the image behind this <br /> division element. <br /> Vertically, horizontally <br /> or both </div> <select onchange="ChangeRepeat (this);" size="4"> <option selected="selected" />repeat <option />no-repeat <option />repeat-x <option />repeat-y </select> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
background
backgroundAttachment
backgroundColor
backgroundImage
backgroundPosition
backgroundPositionX
backgroundPositionY
backgroundAttachment
backgroundColor
backgroundImage
backgroundPosition
backgroundPositionX
backgroundPositionY
External links:
background-repeat (MSDN)
background-repeat (Mozilla Developer Center)
background-repeat (Safari Reference Library)
background-repeat (W3C)
background-repeat (Mozilla Developer Center)
background-repeat (Safari Reference Library)
background-repeat (W3C)
User Contributed Comments