The CSS selectoris what in HTML is called the tag or element— the items
in HTML code that are surrounded by angle brackets (such as <h2>, <p>,
or <tr>).
A single CSS ruleis made up of a minimum of three parts:
The selector, such as p, which tells the browser which HTML tag
(elements) the rule should be applied to later in the HTML code.
The property, such as color. This is what HTML calls an attribute.
Usually it’s the name of a quality of an element, such as its height,
font-style, color, and so on.
The value of the property, such as blue. This is the actual data specify-
ing the change you are making to the appearance (usually) of the ele-
ment, such as 45 pixels, Times Roman, or yellow.
The preceding list describes the simplest CSS rule. You can however, group
multiple selectors for a single style (h1, h2,pcan all be specified in a single
rule as green, for example). Likewise, you can group multiple properties in a
single rule, as I did in a previous example:
p {
color: blue;
text-align: right;
font-family: courier;
}
Like HTML, CSS code can be freely rearranged whatever way suits you — lines
can be formatted in any fashion. The following rule is interpreted identically
to the previous example:
p {color: blue;
text-align: right; font-family: courier;}
These two rules mean exactly the same thing to the browser, but CSS pro-
grammers have their personal preferences about formatting.
Properties refer to attributes .............................................................
The CSS property is what HTML calls the attribute— the name of the quality
that you are specifying (such as color or font size). Many computer languages
also use the term property in this same way.
Finally, the CSS valueis the actual data about the property: In other words,
blackor greencan be values of the colorproperty. The value in CSS is the
same concept as the value held in a variable or constant in computer pro-
gramming. Computer programming languages use the term value in the same
way that CSS does.
34 Part I: The ABCs of CSS