04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

How do I specify Web colors?<br />

Let me count the ways...<br />

<strong>CSS</strong> gives you a few ways to specify colors. You can specify the<br />

name of a color, specify a color in terms of its relative percentages<br />

in red, green and blue, or you can specify your color using a hex<br />

code, which is shorthand for describing the red, green, and blue<br />

components of the color.<br />

While you might think that the Web would have decided on one<br />

format by now, all these formats are commonly used, so it’s good<br />

to know about them all. However, hex codes are by far the most<br />

common way of specifying Web colors. But, remember that all<br />

these ways of specifying color ultimately just tell the browser the<br />

amount of red, green, and blue that goes into a color.<br />

Let’s work through each method of specifying colors in <strong>CSS</strong>.<br />

Specify color by name<br />

The most straightforward way to describe a color in <strong>CSS</strong> is just to use<br />

its name. But, as you know, there are only seventeen colors that can<br />

be specified this way. Let’s say you want to specify the color “silver”<br />

as the background color of a body element; here’s how you write<br />

that in <strong>CSS</strong>:<br />

body {<br />

background-color: silver;<br />

}<br />

Here’s the body rule. And the background-color<br />

property.<br />

And the color<br />

written as a name.<br />

So, to specify a color by name, just type the color name as the<br />

value of the property. <strong>CSS</strong> color names are case-insensitive, so you<br />

can type silver, Silver, or SILVER and all will work. Here are the<br />

seventeen predefined colors in <strong>CSS</strong>. Remember these are just names<br />

for predefined amounts of red, green, and blue.<br />

Color in a book happens by light bouncing off the printed page.<br />

On a computer, the light is emitted by the screen, so these<br />

colors will look slightly different in your Web pages.<br />

styling <strong>with</strong> fonts and colors<br />

Aqua<br />

Blue<br />

Gray<br />

Lime<br />

Navy<br />

Orange<br />

Red<br />

Teal<br />

Yellow<br />

Black<br />

Fuchsia<br />

Green<br />

Maroon<br />

Olive<br />

Purple<br />

Silver<br />

White<br />

you are here 367

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

Saved successfully!

Ooh no, something went wrong!