XML technologies / CSS / Advanced websites with CSS / CSS property reference / background-image

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The property background-image assigns a background image to an HTML element. Its position and tiling can be set with the properties background-position and background-repeat.

A parent element’s background image remains visible through its descendants unless their backgrounds are overridden with their own declarations of background-color or background-image.

Inherited: no

See also: background-attachment, background-color, background-position, background-repeat

Values

A URL or none. CSS places a URL inside the tag url(); HTML-style quotation marks are not valid.

Default value: none

Compatibility

CSS version: 1

Works in all CSS-capable browsers, including Internet Explorer 4 and later and Netscape 4 and later.

Netscape 4 does not display a background image across an entire block element unless a border (border) is also defined (a border width of 0px is sufficient). Even with a visible border, a transparent gap remains between the padding and border. Netscape’s proprietary property layer-background-image can fill this gap separately with the background image.

Examples

The following rules add a background image using a relative path, an absolute path and a complete HTTP path respectively:

body {
  background-image: url(../images/textur.gif);
}
body {
  background-image: url(/images/textur.gif); 
} 
body {
  background-image: url(http://www.mysite.com/images/textur.gif);
}

  

 

 

 

back to top