HTML and CSS Reference
In-Depth Information
Selector Syntaxes
A CSS selector identifies those markup elements to which the CSS style(s) will be applied. Specific element groups are
styled by various types of selectors. The general structure of a CSS rule (or CSS ruleset for multiple declarations), as
shown in Figure 5-1 , can be written with the pseudocode shown in Listing 5-6.
Figure 5-1. CSS rule structure
Listing 5-6. Pseudocode of CSS Rulesets
selector [, selector2, ..., selectorn] [:pseudo-class] {
property: value;
[property2: value2;
propertym: valuem;]
Multiple declarations of the same selector can be organized into groups separated by semicolons ( ; ).
although it is legal to omit the semicolon after the last declaration in a ruleset, it is strongly recommended to
always provide it. It makes maintenance and modifications easier and becomes handy when a declaration is moved
to another location in the CSS.
For example, the rules in Listing 5-7 can be written as shown in Listing 5-8.
Listing 5-7. It Is Not Optimal to Declare Rules of the Same Element Separately
h1 { font-weight: bold }
h1 { font-size: 1.6em }
h1 { font-family: Verdana, sans-serif }
Listing 5-8. Rules of the Same Element Should Be Grouped
h1 {
font-weight: bold;
font-size: 1.6em;
font-family: Verdana, sans-serif;
Search WWH ::

Custom Search