Cover | Table of Contents | Colophon
<B> and <I> started
to creep into the language. Suddenly, a structural language started
to become presentational.
<H1>Leaping Above The Water</H1>
H1
into a table and load it up with a ton of other tags like
<HTML>
<HEAD>
<TITLE>Eric's World of Waffles</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="sheet1.css" TITLE="Default">
<STYLE TYPE="text/css">
@import url(sheet2.css);
H1 {color: maroon;}
BODY {background: yellow;}
/* These are my styles! Yay! */
</STYLE>
</HEAD>
<BODY>
<H1>Waffles!</H1>
<P STYLE="color: gray;">The most wonderful of all breakfast foods is
the waffle-- a ridged and cratered slab of home-cooked, fluffy
goodness...
</P>
</BODY>
</HTML>
<LINK REL="stylesheet" TYPE="text/css" HREF="sheet1.css" TITLE="Default">
LINK tag. The LINK tag is a
little-regarded but nonetheless perfectly valid tag that has been
hanging around the HTML specification for years, just waiting to be
put to good use. Its basic purpose is to allow HTML authors to
associate other documents with the document containing the
LINK tag. CSS1 uses it to link style sheets to the
HTML document; in Figure 1-2, a style sheet called
LINK element has
been universally supported, as have both the STYLE
element and attribute. @import didn't fare
so well, though, being ignored outright by Navigator 4. This is not
such a major tragedy, annoying though it might be, since the
LINK element will still let you bring external
style sheets into play.
<FONT
COLOR="green"> tags with new ones that have
different shades of green. Meanwhile, all the other administrators
have started to think of their own ways to nitpick the design to
death. Maybe the headings should be dark blue instead of green, or
perhaps the sidebar's background is the wrong color, or maybe
the company logo ought to be used for list-item bullets instead of
those little black dots that everyone else uses.
FONT tags and
BGCOLOR attributes. That can take forever if you
have a lot of documents, or a really complicated design, and if you
suddenly head in a different direction, you can spend almost as much
time cleaning up the residue of your old assumptions as you do on
actual creative design work.
H2 elements
appear gray. Using straight HTML, you'd have to do this by
inserting <FONT
color="gray">...</FONT> tags in all your
H2 elements, something like this:
<H2><FONT COLOR="gray">This is H2 text</FONT></H2>
H2 elements,
this can become very tedious to type. If you later decide that you
want to change all the H2s to be green instead of
gray, then the task becomes even worse because you have to find all
of those H2s and change the value of each and
every FONT tag to be gray.
H2 {color: gray;}
H2 elements to be
colored gray. If you want to change this to another color, then the
alteration of this single rule will affect all H2s
in the document:
H2 {color: silver;}
H2 elements
and paragraphs should have gray text. The easiest way to accomplish
this is to use the following.
H2, P {color: gray;}
H2 and P
selectors on the left side of the rule and separating them with a
comma, we've defined a rule
where the style on the right (color:
gray;) is applied to both selectors. The comma
tells the browser that there are two different selectors involved in
the rule. Leaving out the comma would give the rule a completely
different meaning, which we'll explore later, in Section 2.5.1.
BODY, TABLE, TH, TD, H1, H2, H3, H4, P, PRE, STRONG, EM, B, I {color: gray;}
H1 {color: purple;}
H2 {color: purple;}
H3 {color: purple;}
H4 {color: purple;}
H5 {color: purple;}
H6 {color: purple;}
H1, H2, H3, H4, H5, H6 {color: purple;}
P {font-weight: bold;}
A {color: maroon;}
<HTML> <HEAD> <BASE HREF="http://www.meerkat.web/"> <TITLE>Meerkat Central</TITLE> </HEAD> <BODY> <H1>Meerkat <EM>Central</EM></H1> <P> Welcome to Meerkat <EM>Central</EM>, the <STRONG>best meerkat web site on <A HREF="inet.html">the <EM>entire</EM> Internet</A></STRONG>!</P> <UL> <LI>We offer: <UL> <LI><STRONG>Detailed information</STRONG> on how to adopt a meerkat</LI> <LI>Tips for living with a meerkat</LI> <LI><EM>Fun</EM> things to do with a meerkat, including: <UL> <LI>Playing fetch</LI> <LI>Digging for food</LI> <LI>Hide and seek</LI> </UL> </LI> </UL> <LI>...and so much more!</LI> </UL> <P> Questions? <A HREF="mail to:suricate@meerkat.web">Contact us!</A> </P> </BODY> </HTML>
H1
element, for example, then that color is applied to all text in the
H1, even the text enclosed within child elements
of that H1:
H1 {color: gray;}
<H1>Meerkat <EM>Central</EM></H1>
H1 text and the EM text are
colored gray because the value of
color inherits into the EM
element. This is very likely what the author intended, which is why
inheritance is a part of CSS.
EM text would
be black, not gray.
color:
gray for UL elements. What we
expect is that a style that is applied to a UL
will be applied to its list items as well, and to any content of
those list items. Thanks to inheritance, that's exactly what
does happen, as Figure 2-24 demonstrates:
UL {color: gray;}
.grape {color: purple;}
H1 {color: red;}
<H1 CLASS="grape">Meerkat <EM>Central</EM></H1>
H1 and
.grape can both match the H1
element shown, which one wins? As it happens,
.grape is the correct answer, and so the
H1 element will be colored purple. This happens
because of the specificity of the two rules, and
the rules CSS has to deal with such situations.
H1) has a specificity of 1, class selectors
have a specificity of 10, and ID selectors a specificity of 100. Thus
the following rules would have the noted specificity:
H1 {color: red;} /* specificity = 1 */
P EM {color: purple;} /* specificity = 2 */
.grape {color: purple;} /* specificity = 10 */
P.bright {color: yellow;} /* specificity = 11 */
P.bright EM.dark {color: brown;} /* specificity = 22 */
#id216 {color: blue;} /* specificity = 100 */
#id216 has a much higher
specificity, and therefore more weight, than any of the others
listed. In cases where more than one rule can apply to an element,
the styles with the higher weight win out.
BODY {background: black;}
LI {color: gray;}
UL.vital {color: white;}
vital, in which case they'll be white.
However, as Figure 2-26 demonstrates, this is not
the case.
H1 {color: red;}
H1 {color: blue;}
red and blue. It has to be one
or the other. But which?
!important are given higher weight
than those that are not. Also sort by origin all declarations
applying to a given element. There are three
origins: author,
reader, and user agent. Under normal circumstances, the
author's styles win out over the reader's styles.
!important author styles win out over important
reader styles in CSS1, but in CSS2, !important
reader styles are stronger than any other styles. Either author or
reader styles will override user agent styles.
DIVs, and BODY.
Replaced elements, such as images and form inputs, can be block-level
elements but usually are not. Each block-level element is displayed
on a line by itself, so to speak, beginning on a new line and forcing
any element after it to do the same. Block-level elements can only be
children of other block-level elements, and then only in certain
circumstances.
A, EM ,
SPAN, and most replaced elements, such as images
and form inputs. They do not force anything to start on a new line,
not even themselves, and can be the children of any other element.
LI element. These are specially
defined to have presentation aspects such as a "marker"
(a bullet, letter, or number) and a certain sense of ordering, if
such an element appears within an ordered list of some kind. Thus,
list items within such a list can be automatically numbered, based on
their context within the document.
display.
red or purple,
or employ a vaguely cryptic method using hexadecimal codes. Well,
both of those methods for describing colors can be found in CSS, as
well as some other methods that are only moderately complex.
red or purple,
or employ a vaguely cryptic method using hexadecimal codes. Well,
both of those methods for describing colors can be found in CSS, as
well as some other methods that are only moderately complex.
|
aqua
|
gray
|
navy
|
silver
|
|
black
|
green
|
olive
|
teal
|
|
blue
|
lime
|
purple
|
white
|
|
fuchsia
|
maroon
|
in (inches), or
pt (points). The only exception to this rule is a
length of 0 (zero), which need not always be
followed by a unit.
in)cm)mm)%). For example:
H1 {font-size: 18pt;}
H1.tall {line-height: 150%;}
line-height of all
H1 elements with a class of
tall to be half again as large as normal, as we
see in Figure 3-8.
line-height is exactly 27 points
(18pt times 1.5). This is the same as setting the
line-height to 1.5em , although
neither method is particularly recommended over the other.
@import statement, which is used when importing an
external style sheet—then the general format is:
url(http://server/pathname)
url(pathname)
@import url(http://css1.style.org/example.css);
BODY {background-image: url(hatch.gif);}
deg ), grads
(grad ), and radians (rad ).
For example, a right angle could be declared as
90deg, 100grad , or
1.57rad ; in each case, the values are translated
into degrees in the range 0
through 360. This is also true of negative values, which are allowed.
The measure -90deg is the same as
270deg.
ms) or seconds
(s). Thus, 100ms and
0.1s are equivalent. Time values may not be
negative.
Hz) or megahertz (mHz) and
cannot be negative. The values labels are case-insensitive, so
10mHz and 10mhz are equivalent.
url(...), though, so it's hard to know
exactly what the point was of including a section in CSS2 about how
CSS2 uses URIs instead of URLs.
<FONT> and
<CENTER>, which give you some measure of
control over the appearance and placement of text.
SPACER
tag to get a similar effect. There is a better way, thanks to CSS.
<FONT
face="...">
tags? In fact, the beginning of the "Font Properties"
section of CSS1 begins with the sentence, "Setting font
properties will be among the most common uses of style sheets."