Click to buy
Cascading Style Sheets: The Definitive Guide
By Eric A.
Meyer
Introduction
What a Mess
Rich Styling
Ease of Use
Using Your Styles on Multiple Pages
Cascading
Preparing for the Future
Implementations
Bringing CSS and HTML Together
Summary
Printer Friendly Version
Chapter 1
HTML and CSS
What a Mess
Years later, we have inherited the flaws inherent in this
process. Large parts of HTML 3.2 and HTML 4.0, for example, are devoted to
presentational considerations. The ability to color and size text through the
FONT element, to apply background colors and images
to documents and tables, to space and pad the contents of table cells, and to
make text blink on and off are all the legacy of the original cries for "more
control!"
If you want to know why this is a bad thing, all it takes is a
quick glance at any corporate web site's page markup. The sheer amount of
markup in comparison to actual useful information is astonishing. Even worse,
for most sites, the markup is almost entirely made up of tables and FONT tags, none of which conveys any real semantic
meaning to what's being presented. From a structural standpoint, these pages
are little better than random strings of letters.
For example, let's assume that for page titles, an author is
using FONT tags instead of heading tags like H1, like this:
<FONT SIZE="+3" FACE="Helvetica" COLOR="red">Page Title</FONT>
Structurally speaking, the FONT tag
has no meaning. This makes the document far less useful. What good is a FONT tag to a speech-synthesis browser, for example? If
an author uses heading tags instead of FONT tags,
the speaking browser can use a certain speaking style to read the text. With
the FONT tag, the browser has no way to know that
the text is any different from other text.
Why do authors run roughshod over structure and meaning like
this? Because they want readers to see the page as they designed it. To use
structural HTML markup is to give up a lot of control over a page's
appearance, and it certainly doesn't allow for the kind of densely packed page
designs that have become so popular over the years.
So what's wrong with this? Consider the following:
- Unstructured pages make content indexing inordinately
difficult. A truly powerful search engine would allow users to search just
page titles, or only section headings within pages, or only paragraph text,
or perhaps only those paragraphs that are marked as being important. In
order to do this, however, the page contents must be contained within some
sort of structural markup--exactly the sort of markup most pages lack.
- A lack of structure reduces accessibility. Imagine that
you are blind, and rely on a speech-synthesis browser to browse the Web.
Which would you prefer: a structured page that lets your browser read only
section headings so you can choose which section you'd like to hear more
about; or a page so lacking in structure that your browser is forced to read
the entire thing with no indication of what's a heading, what's a paragraph,
and what's important?
- Advanced page presentation is only possible with some
sort of document structure. Imagine a page in which only the section
headings are shown, with an arrow next to each. The user can decide which
section heading applies to him and click on it, thus revealing the text of
that section.
- Structured markup is easier to maintain. How many times
have you spent long minutes hunting through someone else's HTML (or even
your own) in search of the one little error that is messing up your page in
one browser or another? How much time have you spent writing nested tables
and
FONT tags, just to get a sidebar with white
hyperlinks in it? How many line-break tags have you inserted trying to get
exactly the right separation between a title and the following text? By
using structural markup, you can clean up your code and make it easier to
find what you're looking for.
Granted, a fully structured document is a little plain. Due to
that one single fact, a hundred arguments in favor of structural markup
wouldn't sway a marketing department away from the kind of HTML so prevalent
at the end of the twentieth century. What was needed was a way to combine
structural markup with attractive page presentation.
This concept is nothing new. There have been many style sheet
technologies proposed and created over the last few decades. These were
intended for use in various industries and in conjunction with a variety of
structural markup languages. The concept had been tested, used, and generally
found to be a benefit to any environment where structure had to be presented.
However, no style sheet solution was immediately available for use with HTML.
Something had to be done to correct this problem.
CSS to the Rescue
Of course, the problem of polluting HTML with presentational
markup was not lost on the World Wide Web Consortium (W3C). It was recognized
early on that this situation couldn't continue forever, and that a good
solution was needed quickly. In 1995, they started publicizing a
work-in-progress called CSS. By 1996, it had become a full Recommendation,
with the same weight as HTML itself.
So what does CSS offer us? As of this writing, it offers us two
levels of itself. The first level is Cascading Style Sheets, Level 1 (CSS1),
which was made a full W3C Recommendation in 1996. Soon thereafter, the W3C's
Cascading Style Sheets and Formatting Properties (CSS&FP) Working Group
got to work on a more advanced specification, and in 1998 their work paid off
when Cascading Style Sheets, Level 2 (CSS2) was made a full Recommendation.
CSS2 builds on CSS1 by extending the earlier work without making major changes
to it.
The future is likely to see further advances in CSS, but until
then, let's go over what we already have.
Printer Friendly Version
FONT>
Introduction
What a Mess
Rich Styling
Ease of Use
Using Your Styles on Multiple Pages
Cascading
Preparing for the Future
Implementations
Bringing CSS and HTML Together
Summary