Monday, February 02, 2009

CSS Rules

Writing a CSS rule is easy. Each declaration consists of a selector, a property for the selector, and a value for the property. Below I have the element name div as my selector, property is border property, to which I give a value of, a thin black continous line.

div { border: 1px solid black; }

This statement will draw a box of 1px width around every div in the program. The div selector, being a generic element name, paints with a rather large brush. If you don't want that, you can make your selector more specific by using what's called a "contextual selector". If I forced my div descend from a class then my rule becomes less general and target a smaller subset of div's:

.boxed div { border: 1px solid black; }

will only effect those divs that descend from the class "boxed".

Post a Comment