Click to return to the DHTML, HTML     
background-color Attribut...     background-position Attri...     DHTML Properties    
Web Workshop  |  DHTML, HTML & CSS

background-image Attribute | backgroundImage Property


Sets or retrieves the background image of the object.

Syntax

HTML{ background-image: sLocation }
Scriptingobject.style.backgroundImage [ = sLocation ]

Possible Values

sLocation String that specifies one of the following values:
noneColor of the next parent through which the background is visible.
url(sUrl)Location of the background image, where sUrl is an absolute or relative URL.

The property is read/write with a default value of none; the cascading style sheets (CSS) attribute is not inherited.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see Dynamic Properties.

Remarks

The URL identifies the image file. When setting a background image, you can set a background color to be used when the image is unavailable. When the image is available, it overlays the background color.

This property may be set with other background properties by using the background composite property.

Internet Explorer 3.0 supports the background-image attribute, but only when it's set through the background attribute.

Example

The following examples use the background-image attribute and the backgroundImage property to specify the background's image.

This example uses a call to an embedded (global) style sheet to show and hide the background image.

Sample Code

<STYLE>
    .setUrl  { background-image: url(sphere.jpg) }
    .loseUrl { background-image: url(none) }
</STYLE>
</HEAD> 
<BODY> 
<SPAN STYLE="font-size:14" onmouseover="this.className='setUrl'"
    onmouseout="this.className='loseUrl'">
. . . </SPAN>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

This example uses inline scripting to show and hide the background image.

<SPAN onmouseover="this.style.backgroundImage='url(sphere.jpeg)'">
. . . </SPAN>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
A, ADDRESS, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, currentStyle, custom, DD, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FORM, Hn, HTML, I, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.