As was discussed on the previous page, the declaration of a rule is made up of 2 parts; a property, and a value.

Properties are pretty straightforward even though they differ from element to element. You'll be learning a lot about them in this course and you can look them up in the Stylin' with CSS Appendix on page 255, or any CSS reference.

Values need a bit more explanation.

There are three types of values: words, lengths, and color values. Each must be written correctly in order for the property to take affect.

According to the W3C spec, rules that are incorrectly written are to be ignored by the user agent.

Length Values

Length values describe an element's height, width, thickness, and so on. Length values can be absolute or relative. EXAMPLES

*Technically pixels are "relative," according to the W3C Open in a New Window. "Pixel units are relative to the resolution of the viewing device." But since that range of scalability is so limited, not to mention cumbersome to change, for all practical purposes pixels should be considered to be an absolute measure.

Length Syntax

When writing length values, be sure to specify the unit of measure! There is no space between the number and the unit. Page 61 of the Stylin' book presents a listing of numeric values.

p { font-size: 12px; } h1 { font-size: 1.5em; } li { font-size: 10pt; } hr { width: 75%; }

Many CSS experts suggest using relative units like EM to specify type sizes for the following reasons:

Color Values

There are three types of color values:

Hex and RGB values give the designer the most color options. Use the Visibone Open in a New Window color lab to explore colors. EXAMPLES

Hexidecimal values are preceeded by a hash mark ( # ) and consist of 6 characters:

#88FFAA;

Hex values simply specify the amount of red, green and blue that is blended to create the color. The first 2 digits define the red color value, the next 2 are green and the final 2 are the blue values. A value pair of FF corresponds to 100% (complete color saturation), while a value pair of 7F corresponds to 50%.

If your hex color has the same 2 characters in each pair, it can be abbreviated as a three-digit hex value. In the two examples below, I've added color to the hex value to make the corresponding color pairs more obvious:

#88FFAA; #8FA;
#ff3322; #f32;

Hex color values are NOT case sensitive.

An RGB value is an alternative notation for specifying the amount of red, green and blue that is blended to create the desired color. RGB values are expressed as a decimel or percentage triplet. A value of 255 corresponds to 100% saturation of the color, while 127 (half of 255) corresponds to 50% saturation of the color. For those of us who do not think in hexidecimel, RGB values are easier to visualize and predict. The RGB triplet values are specified within parentheses.

In the examples below, I have added color to the triplets to highlight the corresponding color that the value specifies:

rgb(0,153,153);
rgb(100%,0%,0%);

HINT: When writing RGB styles, don't forget the closing } for the rule's declaration block after the rgb's closing )!

16 Color Names from W3C

Color Names: When using color names, it is safest to stick with the 16 color names given in the W3C specifications.

Even though there are lists of other, more interesting, color names such as peachpuff, bisque and burlywood (!), each browser assigns its own method for handling these names. To be sure that your colors look the same, use HEX or RGB values.

In the past, developers were advised to use "web safe colors Open in a New Window" that were limited to colors with no subtlety at all. Now however, most web experts have agreed that it is no longer necessary to limit colors to this palette. At last!!

The Zen reading this week (if you have the book) will explore more on color and design. There are very good sections on psychological color associations and color, culture, and gender. There are suggestions for developing color palettes for your sites and sections on pattern, texture, contrast and color blindness. Read these pages for ideas and inspiration.

Warning: Don't get hung up in the advanced code!

References