Sams Teach Yourself CSS in 10 Minutes

Adding background-image

The background-image property is used to add a background image to the <body> element.

Values for the background-image property are either a url (to specify the image) or none (when no image is used).

For this lesson, you will use url(chapter6.jpg). The image path can be written with or without quotation marks. The background-image code is shown in Listing 6.3. The results can be seen in Figure 6.1.

Listing 6.3. CSS Code Styling the <body> Element with a Background Image

body { background-image: url(chapter6.jpg); }

Figure 6.1. Screenshot of styled <body>.

Background Images and Internet Explorer 5 for Macintosh

Internet Explorer 5 for Macintosh will not render background-images if quotations are used around image paths. Because quotation marks are not needed, it is simpler and safer to leave them out.

Категории