22.06.2015 Views

o_19octlt3v29m1ul81r9513q81i4ra.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

64 Chapter 4<br />

If you specify a background image, you should also specify a background color. The color<br />

will not be visible unless the image fails to display for some reason, or unless the image<br />

has transparent areas in it. The background color is especially important if you use a dark<br />

background image and a light foreground color; if the image does not appear, the text<br />

still must appear on a dark background to be readable.<br />

To use a background image file, use a style=”background-image: url(image)” attribute<br />

in the opening tag, as you did for foreground and background colors in the<br />

preceding section. For example, to use the background image file called granite.gif that<br />

is located in the same folder as the HTML file, you would write:<br />

<br />

Notice that you must enclose the image file name in parentheses following the url.<br />

The tag can hold many style specifications in a single style= attribute. Separate<br />

them with semicolons, as you did earlier with the foreground and background colors. For<br />

example, to combine the background image, background color, and foreground color in<br />

a single attribute, do the following:<br />

<br />

By default, the background image is repeated both horizontally and vertically to fill the<br />

window. You can force it not to repeat by adding the background-repeat= attribute to<br />

the tag and specifying repeat-x (repeat horizontally only), repeat-y (repeat vertically<br />

only), or no-repeat. For example, to prevent any repeating, use the following:<br />

<br />

By default, the background image scrolls with the text when the user scrolls down the<br />

page. To force the image to stay fixed, add the background-attachment=fixed attribute to<br />

the tag, as follows:<br />

<br />

In this exercise, you will display an image as a Web page background.<br />

SET UP Use the foliage.htm and stucco.jpg files in the practice file folder for this<br />

topic. These practice files are located in the Documents\Microsoft Press\HTML5<br />

SBS\04Lists\SpecifyingImages folder. Open the foliage file in Notepad and in Internet<br />

Explorer.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!