Book HomeCascading Style Sheets: The Definitive GuideSearch this book Sunday 29th of May 2016 09:10:27 PM
would only happen if those faces had the top two weight levelsalready assigned. Otherwise, the user agent might ignore them, andassign 800 and 900 to the Boldface instead, or it might assign them both to one or the other of theBlack variants.

Finally, let's consider a stripped-down version of Times, inwhich there are only two weight variants, TimesRegular and TimesBold,as shown in Table 5-2.

Chapter 1. HTML and CSS

Contents:

The Web's Fall from Grace
CSS to the Rescue
Limitations of CSS
Bringing CSS and HTML Together
Summary

In many ways, the Cascading Style Sheets (CSS) specification represents a unique development in the history of the World Wide Web. In its inherent ability to allow richly styled structural documents, CSS is both a step forward and a step backward -- but it's a good step backward, and a needed one. To see what is meant by this, it is first necessary to understand how the Web got to the point of desperately needing something like CSS, and how CSS makes the web a better place for both page authors and web surfers.

1.1. The Web's Fall from Grace

Back in the dimly remembered early years of the Web (1990 -1993), HTML was a fairly lean little language. It was almost entirely composed of structural elements that were useful for describing things like paragraphs, hyperlinks, lists, and headings. It had nothing even remotely approaching tables, frames, or the complex markup we assume is a necessary part of creating web pages. The general idea was that HTML would be a structural markup language, used to describe the various parts of a document. There was very little said about how these parts should be displayed. The language wasn't concerned with appearance. It was just a clean little markup scheme.

Then came Mosaic.

Suddenly, the power of the World Wide Web was obvious to almost anyone who spent more than ten minutes playing with it. Jumping from one document to another was no harder than pointing the mouse cursor at a specially colored bit of text, or even an image, and clicking the mouse button. Even better, text and images could be displayed together, and all you needed to create a page was a plain text editor. It was free, it was open, and it was cool.

Web sites began to spring up everywhere. There were personal journals, university sites, corporate sites, and more. As number of sites increased, so did the demand for new HTML tags that would allow one effect or another. Authors started demanding that they be able to make text boldfaced, or italicized.

At the time, HTML wasn't equipped to handle these sorts of desires. You could declare a bit of text to be emphasized, but that wasn't necessarily the same as being italicized -- it could be boldfaced instead, or even normal text with a different color, depending on the user's browser and their preferences. There was nothing to ensure that what the author created was what the reader would see.

As a result of these pressures, markup elements like <B> and <I> started to creep into the language. Suddenly, a structural language started to become presentational.

1.1.1. 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:

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.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.

<INPUT TYPE="checkbox" NAME="c3" VALUE="one ">

This allows you to dispense with the classes altogether, at least in this instance. See the Chapter 10, "CSS2: A Look Ahead", for more details on how this kind of selector works.

WARNING

Navigator 4 does not apply colors to form elements, but setting the colors for form elements does work in Internet Explorer 4 and 5, and Opera 3.5 and later.

inside unordered lists? You get the results shown in Figure 11-21, that's what.

Figure 11-21

Figure 11-21. Help me

Wow! What happened? Simply put, each nested list cuts the font sizeby a quarter. Let's assume the document's basefont-size is 12pt. Therefore,at the top level, the font's size will be three-quarters ofthat, or 9pt. All well and good, except the nextlevel down will see a reduction to 6pt, and thenext level to 4pt, and so on. Once the text goes won't be easy to get everything just the way it is on the page,but we'll see what we can do.

First, let's take apart the page's layout and determinewhat to eliminate. Since there are no pages on the Web, we can dropthe page number. Also, the outer margins can be modified to suit ourneeds, since we don't have to worry about leaving extra spacefor the staples and so forth. However, the editors want to keep thetwo-column layout, the picture placement, and the general appearanceof the text, so we'll have to bear that in mind. being independent of any presentational concepts. After all, you might decide later to make all subsection titles dark red instead of dark blue, and the statement H2.dkblue {color: maroon;} is a little silly.

From this simple example, we draw the general lesson that when you're planning to use styles, it's generally to your advantage to plan ahead and use all of the tools you can. To take the preceding example a little further, suppose that a navigational bar min-width: 20em; min-height: 30em;

Of course, this still isn't a very good solution, since it forces the element to be at least 20em wide by 30em tall. Here's a better one:

top: 10%; bottom: auto; left: 50%; right: 10%; height: auto; min-width: 15em;

Here we have a case where the element should be 40% as wide as the containing block but can never be less than 15em wide. We've also changed the bottom and height so that they're automatically