HTML and CSS Reference
In-Depth Information
Element Selectors
An element selector is most often an HTML element, but not always. For example, if
a CSS file contains styles for an XML document, element selectors might look some-
thing like this:
QUOTE {color: gray;}
BIB {color: red;}
BOOKTITLE {color: purple;}
MYElement {color: red;}
In other words, the elements of the document serve as the most basic selectors. In XML,
a selector could be anything, since XML allows for the creation of new markup lan-
guages that can have just about anything as an element name. If you're styling an HTML
document, on the other hand, the selector will generally be one of the many HTML
elements such as
p
,
h3
,
em
,
a
, or even
html
itself. For example:
html {color: black;}
h1 {color: gray;}
h2 {color: silver;}
The results of this style sheet are shown in
Figure 1-1
.
Figure 1-1. Simple styling of a simple document
Once you've globally applied styles directly to elements, you can shift those styles from
one element to another. Let's say you decide that the paragraph text, not the
h1
ele-
ments, in
Figure 1-1
should be gray. No problem. Simply change the
h1
selector to
p
:
html {color: black;}
p {color: gray;}
h2 {color: silver;}
The results are shown in
Figure 1-2
.