10.07.2017 Views

246996016-HTML5-Step-by-Step

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Choosing Background and Foreground Colors 61<br />

only the following numeric values for red, green, and blue: 0, 51, 102, 153, 204, and 255.<br />

To see full-color samples of all the web-safe colors, refer to Documents\Microsoft Press\<br />

<strong>HTML5</strong> SBS\Reference\websafe.htm.<br />

Yet another way to express color values is <strong>by</strong> using extended names. These are similar<br />

to the basic color names, but there are a lot more of them. Officially, they are supported<br />

only <strong>by</strong> Internet Explorer, but in reality, most modern browsers recognize them. To<br />

see full-color samples of all the extended colors, refer to Documents\Microsoft Press\<br />

<strong>HTML5</strong> SBS\Reference\extended.htm.<br />

Note Not all named colors in the extended set are web-safe; in fact, most of them aren’t.<br />

Colors from the extended set are convenient because they are named, but web-safe colors are<br />

often a better choice.<br />

Applying a Background Color<br />

To specify a background color for an entire page, insert the style ”background-color:<br />

color” attribute into the opening tag. For example, to make the background of<br />

an entire page yellow, use the following:<br />

<br />

You can use the color name, the RGB value, or the hexadecimal value. Therefore, the following<br />

are equivalent to the code just shown:<br />

<br />

<br />

Applying a Foreground Color<br />

The foreground color is the default text color for the page. You can set the foreground<br />

color <strong>by</strong> using the style ”color: color” attribute. It can be combined with the attribute for<br />

the background color in a single style statement. For example, to set yellow text on a<br />

navy blue background, use the following:<br />

<br />

When you combine two attributes in a single style statement, you separate them with a<br />

semicolon, as shown in the preceding example.<br />

Note This method of applying background and foreground colors uses styles, which you will<br />

learn more about in Chapter 6. <strong>HTML5</strong> does not support the older method of applying colors<br />

within the tag.<br />

In this exercise, you will change the foreground and background colors of a Web page.

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

Saved successfully!

Ooh no, something went wrong!