backgroundImage style property
Specifies or returns the image to use as the background of the object.
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-image |
Possible values:
The type of this property is string.
One of the following values:
Where URI specifies the location of the image file. | |||||||
Takes the value of this property from the computed style of the parent element. | |||||||
Default. Specifies that the current element does not have a background image. |
Default: none.
Example HTML code 1:
This example illustrates the use of the background-image property:
|
||||
<head> <style> .example { background-image: url("bg.jpg"); background-repeat: repeat; width: 300px; height: 200px; overflow: scroll; } </style> </head> <body> <div class="example"> Some content ..... <br /> ..... <br /> ..... <br /> Some content ..... <br /> ..... <br /> ..... <br /> Some content ..... <br /> ..... <br /> ..... <br /> Some content ..... <br /> ..... <br /> ..... <br /> </div> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the backgroundImage property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeImg () { div = document.getElementById ("myDiv"); input = document.getElementById ("myInput"); alert (input.value); div.style.backgroundImage = "url('" + input.value + "')"; } </script> </head> <body> <div id="myDiv">Change the background-image</div> Please set a .gif, .png, .jpg or a .bmp file to see the effect. <input id="myInput" type="file" /> <button onclick="ChangeImg ()">Change image</button> </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
backgroundPosition
backgroundPositionX
backgroundPositionY
backgroundRepeat
backgroundAttachment
backgroundColor
backgroundPosition
backgroundPositionX
backgroundPositionY
backgroundRepeat
External links:
background-image (MSDN)
background-image (Mozilla Developer Center)
background-image (Safari Reference Library)
background-image (W3C)
background-image (Mozilla Developer Center)
background-image (Safari Reference Library)
background-image (W3C)
User Contributed Comments