Appendix A. CSS Property Reference

Mastering Cascading Style Sheets involves knowing how to use a large number of CSS properties that control the appearance of text, images, tables, and forms. To help you in your quest, this appendix gives you a summary of the properties and values you'll use to create your own styles. This list covers nearly all of the CSS 2.1 standard properties—the ones that most web browsers support.

Note

This appendix leaves out properties that no (or hardly any) browsers recognize. Otherwise, the following descriptions mention the browsers with which each property works. For full details straight from the horse's mouth, visit the World Wide Web Consortium's CSS 2.1 specification at www.w3.org/TR/CSS21. You can read about some of the newer CSS 3 properties in Chapter 16. (They don't work in all browsers.)

Every CSS property has a corresponding value. The color property, which formats font color, requires a color value to specify which color you want to use. The property color: #FFFFFF; creates white text. Different properties require different types of values, but they come in four basic categories: colors, lengths and sizes, keywords, and URLs.

You can assign colors to many different properties, including those for font, background, and borders. CSS provides several different ways to specify color.

Computer monitors create colors using a mixture of red, green, and blue light. These RGB values can create (nearly) the full spectrum of color. Almost every design, illustration, and graphics program lets you specify colors using RGB, so it's easy to transfer a color from one of those programs to a CSS property. CSS represents RGB values in several ways:

It doesn't matter which method you use—they all work. For consistency's sake, you should pick one way of specifying RGB values and stick with it. The Windows and Mac operating systems both have color pickers that let you find the perfect color from a palette of millions, and then show you the RGB value. Alternatively, you can use this free online color picker: www.ficml.org/jemimap/style/color/wheel.html. Or, for more advanced color picking (including the ability to create and save a pallet of colors), check out http://kuler.adobe.com.

CSS provides many different ways to measure the size of type, the width of a box, or the thickness of a borderline. To indicate type size, you can use inches, picas, points, centimeters, millimeters, em-heights, ex-heights, pixels, and percentages. However, even though there are a lot of options, most don't apply to the world of onscreen display, for reasons discussed on Using Pixels. You really need to think about these three only—pixels, ems, and percentages.

Instead of color or size, many properties have their own specific values that affect how the properties display and are represented by keywords. The text-align property, which aligns text on screen, can take one of four keywords: right, left, center, and justify. Since keywords vary from property to property, read the property descriptions that follow to learn the keyword appropriate to each property.

One keyword, however, is shared by all properties—inherit. This keyword lets you force a style to inherit a value from a parent element. You can use the inherit keyword on any property. This keyword gives you the power to make styles inherit properties that aren't normally inherited from parent tags. For instance, say you use the border property to add a border around a paragraph. Other tags, such as <em> and <strong>, inside the <p> tag don't inherit this value, but you can force them to do so with the inherit keyword:

em, strong {
  border: inherit;
}

That way, the em and strong tags display the same border value as their parent <p> tag. So the <em> and <strong> elements of the paragraph each get their own borders, as does the entire paragraph, so you'd end up with boxes within boxes (a good reason why that property isn't inherited normally). If you change the <p> tag's border value to a different color or thickness, the <em> and <strong> tags inherit that value and display the same type of border, too.