A Complete Guide to Web Design

(やまだぃちぅ) #1
390 Chapter 23 – Cascading Style Sheets

Cascading Style Sheets


Web Design in a Nutshell, eMatter Edition


  • Style is separate from structure.HTML is designed for indicating the structure
    of a document, to which presentation is applied by the end user’s browsing
    device. Over recent years, however, HTML has been extended to provide
    greater control over presentation (thetag being the most infamous
    example). Style sheets, when done correctly, mark the return to the original
    intention of HTML by removing presentation instructions from HTML and
    placing them in a separate, optional area.

  • Potentially smaller documents. Placing font specifications once at the begin-
    ning of the document instead of using adescription for every individ-
    ual element can drastically cut down on the number of characters in the
    document, and thus its file size. As always with the Web, it is desirable to
    keep file sizes (and download times) as small as possible.

  • Easier site maintenance.It is possible to link multiple HTML pages to a single
    style sheet, which means you can make style changes to hundreds or thou-
    sands of web pages by editing a single file.


Disadvantages


As of this writing, there is one major drawback to implementing style sheets:
Browser support!First, style sheet information is not supported in browser versions
earlier than Microsoft Internet Explorer 3.0 or Netscape Navigator 4.0. That is not
as frustrating as the inconsistency of support among browsers and versions that
claim they do support CSS.
The World Wide Web Consortium first published its recommendation for style
sheets in 1996 and they were first implemented by Internet Explorer 3.0. Since
then, as usual, Microsoft and Netscape have chosen diverging paths in the proper-
ties their browsers support and the way those properties are presented. And, of
course, each browser’s support varies, making universal and browser-safe style
sheet implementation a near impossibility at this time.
The browser-support charts in Appendix E,CSS Compatibility, are evidence of the
gap in style sheet implementations. Unfortunately, this means that style sheets
cannot be relied upon for crucial display instructions for web sites with a general
audience, who are likely to still be using older browser versions.

Strategies for Using Style Sheets Today


The browser-support problem is a major impediment to implementing style sheets
on a wide-scale basis, especially for commercial or consumer-oriented sites.
However, that does not mean that you should abandon them completely. There
are ways to take advantage of style sheets today, or at least prepare for a time
when they can be relied upon completely.


  • Include end tags.While current browsers don’t mind if you leave off the


    or
  • tag, style sheets (and other advanced web technologies such as
    XML) do mind. It is necessary to have clearly defined text elements, including
    both tags. If you think you may be adding style sheet functionality to your site
    in the future, get ready by closing all your tags today.