h1 {font-weight: bold font: 28pt arial; color: green;}
</style>
</head>
<body>
<h1>a headline</h1>
</body>
</html>
But notice that the semicolon is missing after bold. The result is that Internet
Explorer becomes confused and fails to recognize font: 28pt Arialas a
value that can be used with the font-weightproperty (which indeed it cannot
be). So the browser simply ignores the fontproperty and the associated 28pt
Arialvalue. It instead uses the default H1 font instead of the Arial you wanted.
Likewise, the requested size of 28 points is ignored and the default font size is
used instead (which is likely to be smaller than you wanted in this case).
As you no doubt guessed, you can simultaneously group selectors and decla-
rations, like this:
h1, h2, h3, h4 {color: green; background: white; font-family:
Arial;}
Using Attributes as Selectors ......................................................................
CSS2 defines some new selectors, including attribute selectors. Alas, this kind
of selector is not supported by Internet Explorer (IE), but I’ll cover it. Being
familiar with some CSS technologies that IE doesn’t support is still a good
idea in case IE ever does support them.
And, of course, attribute selectors do work with Netscape 6 or 7, Mozilla, or
Opera 5 or 6. What’s more, CSS can be applied to files other than HTML, such
as XML-based files. XML files often endeavor to use “self-describing” attrib-
utes, so these attributes often end up being useful as selectors.
Attribute selectors can expand the utility and flexibility of class and ID attrib-
utes, in addition to allowing you the freedom to try some useful tricks.
For example, recall that when you use class selectors, CSS compares the
selector to each HTML tag — and finds a match only when a class name in
the HTML is identical to a class name in the CSS rule (class names you make
up, such as bodytext, alert, highlight, warningand so on). Here is a
typical class selector. It defines a style (display red) that matches any <p>tag
with class = “alert”later in the HTML:
50 Part I: The ABCs of CSS