|
|
Cascading Style Sheets: HTML and CSS Using Your Styles on Multiple PagesBut wait--there's more! Not only can you centralize all of the style information for a page in one place, but you can also create a style sheet that can then be applied to multiple pages--as many as you like. This is done by a process in which a style sheet is saved to its own document, and then imported by any page for use with that document. Using this capability, you can quickly create a consistent look for an entire web site. All you have to do is link the single style sheet to all of the documents on your web site. Then, if you ever want to change the look of your site's pages, you need only edit a single file and the change will be propagated throughout the entire server--automatically! Consider a site where all of the headings are gray on a white background. They get this color from a style sheet that says:
Now, let's say this site has 700 pages, each one of which uses the style sheet that says headings should be gray. At some point, it's decided that headings should be white on a gray background. So the site's webmaster edits the style sheet to say:
Then he saves the style sheet to disk, and the change is made.
That sure beats having to edit 700 pages to enclose every heading in a table
and a CascadingAnd that's not all! CSS also makes provisions for conflicting rules; these provisions are collectively referred to as the cascade. For instance, take the previous scenario in which you're importing a single style sheet into a whole bunch of web pages. Now inject a set of pages that share many of the same styles, but also have specialized rules that apply only to them. You can create another style sheet that is imported into those pages, in addition to the already existing style sheet, or you can just place the special styles into the pages that need them. For example, you might have one page out of the 700 where headings should be yellow on dark blue instead of white on gray. In that single document, then, you could insert this rule:
Thanks to the cascade, this rule will override the imported rule for white-on-gray headings. By understanding the cascade rules and using them to your advantage, you can create highly sophisticated sheets that come together to give your pages a professional yet easily changed look. This ability is not confined to just the author. Web surfers (or readers) can, in some browsers, create their own style sheets (called reader style sheets, oddly enough) that will cascade with the author's styles as well as the styles used by the browser. Thus, a reader who is color-blind could create a style that makes hyperlinks stand out:
A reader style sheet could contain almost anything: a directive to make text large enough to read, if the user has impaired vision; rules to remove images for faster reading and browsing; even styles to place the user's favorite picture in the background of every document. (This isn't recommended, of course, but it is possible.) This lets readers customize their web experience without having to turn off all of the author's styles. Between importing, cascading, and its variety of effects, CSS becomes a wonderful tool for any author or reader. Compact File SizeBesides the visual power of CSS and its ability to empower both
author and reader, there is something else about it that your readers will
like. It can help keep document sizes as small as possible, thereby speeding
download times. How? As we've mentioned, a lot of pages have used tables and
Preparing for the FutureHTML, as I previously pointed out, is a structural language, while CSS is its complement: a stylistic language. Recognizing this, the World Wide Web Consortium (W3C), the body that debates and approves standards for the Web, is beginning to remove stylistic tags from HTML. The reasoning for this move is that style sheets can be used to create the effects that certain HTML tags provide, so who needs them? As of this writing, the HTML 4.0 specification has a number of
tags that are deprecated; that is, they are in the process of being phased out
of the language altogether. Eventually, they will be marked as obsolete, which
means that browsers will be neither required nor encouraged to support them.
Among the deprecated tags are As if that weren't enough, there is the very strong possibility
that HTML will be gradually replaced by the Extensible Markup Language (XML).
XML is much more complicated than HTML, but it is also far more powerful and
flexible. Despite this, XML does not, of itself, provide any way to declare
style tags such as |
|
|
|
|
||||||||