HTML and CSS Reference
In-Depth Information
In versions previous to IE7, Internet Explorer for both platforms has
problems with correctly handling multiple class selectors. In these older
versions, although you can select a single class name out of a list, se-
lecting based on multiple names in a list does not work properly. Thus,
p.warning would work as expected, but would match
any p elements that have a class attribute with the word help because
it comes last in the selector. If you wrote , then older
versions of Explorer would match any p elements that have warning in
their class value, whether or not help appears in the same value.
ID Selectors
In some ways, ID selectors are similar to class selectors, but there are a few crucial
differences. First, ID selectors are preceded by an octothorpe ( # )—also known as a
pound sign (in the US), hash mark, or tic-tac-toe board—instead of a period. Thus,
you might see a rule like this one:
*#first-para {font-weight: bold;}
This rule produces boldfaced text in any element whose id attribute has a value of
first-para .
The second difference is that instead of referencing values of the class attribute, ID
selectors refer, unsurprisingly, to values found in id attributes. Here's an example of
an ID selector in action:
*#lead-para {font-weight: bold;}
<p id="lead-para">This paragraph will be boldfaced.</p>
<p>This paragraph will NOT be bold.</p>
Note that the value lead-para could have been assigned to any element within the
document. In this particular case, it is applied to the first paragraph, but you could
have applied it just as easily to the second or third paragraph.
As with class selectors, it is possible to omit the universal selector from an ID selector.
In the previous example, you could also have written:
#lead-para {font-weight: bold;}
The effect of this selector would be the same.
Another similarity between classes and IDs is that IDs can also be selected independ-
ently of an element. There may be circumstances in which you know that a certain ID
value will appear in a document, but you don't know the element on which it will
appear (as in the plutonium-handling warnings), so you'll want to declare standalone
ID selectors. For example, you may know that in any given document, there will be an
element with an ID value of mostImportant . You don't know whether that most im-
portant thing will be a paragraph, a short phrase, a list item, or a section heading. You
know only that it will exist in each document, occur in an arbitrary element, and appear
no more than once. In that case, you would write a rule like this:
Search WWH ::

Custom Search