Chapter 42. Adding Cascading Style Sheets


Cascading Style Sheets (CSS) describe the style or appearance of elements on a Web page. You can use CSS to redefine the way the browser displays an HTML tag or sequence of tags, or you can build entirely new styles and apply them to whatever pieces of content you like. In this regard, CSS is extremely useful in separating the structure of a documentthe purely technical description of a Web page that identifies individual pieces of content as particular elements, or types of things: paragraphs, images, headers, quotes, and so onfrom the presentation of the documentwhat each element looks like in a browser.

GEEKSPEAK

Cascading Style Sheets describe the style or appearance of elements on a Web page. The structure of a page is its technical description of which pieces of content are what kinds of things (called elements). The presentation of the page is how the page looks in a browser. In theory, HTML handles the structure of the page, and CSS handles the presentation, although HTML contains a number of presentation tags that have nothing to do with structure, much to the chagrin of coding-minded Web builders.


When HTML first came out, it was supposed to be a structural language, with the browser software determining what each element looked like. The role of a Web builder was simply to identify what pieces of content were which types of thingsthat is, to describe the structure of the pageand the browser handled the presentation. Graphically savvy Web builders found this way of working unacceptable. They demanded more and more control over the look of a Web page, until HTML itself became a mishmash of structural elements and presentation elements that had nothing to do with structure at all. To coding-minded Web builders like the fine folks at the W3C, this way of working was equally unacceptable.

Enter CSS, which, at least in theory, satisfies both types of Web people. The graphic heads get more and better design choices for pixel-perfect control over how a Web page looks, and the coding heads have a way to reclaim HTML as a purely structural language. The downside is that, although CSS has been around for years, it is still an emerging technology. Graphic heads were slow to embrace it, because it is very code-oriented, and it is harder and less intuitive to use than HTML markup. It assumes a level of technical understanding that many visually oriented people never possessed and never bothered to learn in the frenzied days of dot-com startups and IPOs. Further, browser makers like Microsoft and Netscape didn't feel compelled to support CSS with anything like consistency or completeness.

GEEKSPEAK

A style sheet is a block of CSS code that appears between style tags in an HTML document or in a separate CSS file. It consists of style rules, or presentation instructions for the browser. A style rule has a style selector, which is the elements that you are formatting, and a style definition, which tells the browser exactly how to display the selector.


These days are slowly drawing to a close. CSS now enjoys a passably acceptable level of support in the major browsers, so using it effectively has become at least feasible. However, since CSS is nowhere near as stable as the much-maligned HTML presentation tags, he who dabbles in CSS must test and test and test his pages in a variety of browsers to troubleshoot the inevitable glitches, bugs, and inconsistencies that crop up.

TIP

When your style sheet appears in its own file, you don't need the style tags before and after the CSS code. Only use style tags when you embed your style sheet in an HTML document.




Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net