|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Why Style Sheets Are ValuableSimply put, style sheets separate content and presentation. Apart from freeing up HTML to develop as a content description language, it gives Web page designers precise control over how their content appears onscreen. Other benefits of style sheets include
Different Approaches to Style SheetsThe W3C is advocating the Cascading Style Sheet proposal for implementing style sheets. Cascading refers to a certain set of rules that browsers use, in cascading order, to determine how to use the style information. Such a set of rules is useful in the event of conflicting style information because the rules would give the browser a way to determine which style is given precedence. The CSS2 recommendation supports three ways of including style information in a document. These approaches include
Using Multiple ApproachesYou arent limited to using only one of the described style sheet approaches. You can use all three simultaneously if needed. One case in which you may want to do this is on an intranet site where you have the following:
However, you shouldnt use all three approaches in the same document just for the sake of doing it. You should seek to optimize your use of style sheets by choosing the approach or combination of approaches that enables you to apply the styles you want, where you want them, without a lot of unnecessary code. Remember style precedence when using multiple approaches. The idea behind a Cascading Style Sheet is that browsers apply a set of rules in cascading order to determine which style information takes precedence. You need to be aware of these rules so that you do not produce unintended style effects on your pages. In general, youll be fine if you remember the following:
Keeping these rules in mind will make troubleshooting your style sheet setup much easier.
Linking to Style Information in a Separate FileOne important thing to realize is that you dont have to store your style sheet information inside each of your HTML documents. If you anticipate applying the same styles across several HTML pages, it is much more efficient for you to store the style information in one place and have each HTML document linked to it. This makes it much easier to change the formatting of all your pages by changing the style sheet instead of changing every page. Setting Up the Style InformationTo set up a linked style sheet, you first need to create the file with the style information. This takes the form of a plain-text file with style information entries. Each entry starts with an HTML tag, followed by a list of presentation attributes to associate with the rendering of the effect of that tag. Some sample lines in a style sheet file might look like BODY {font: 12 pt New Baskerville; color: navy; margin-left: 0.25in} H1 {font 18 pt Arial; color: red} H2 {font 16 pt Arial; color: CC3366} The first line sets the body text to 12-point New Baskerville type rendered in navy blue with a one-quarter inch left margin. The second line redefines the level 1 heading to 18-point Arial type rendered in red, and the third line sets the level 2 heading to 16-point Arial type, rendered in the color represented by the hexadecimal triplet CC3366.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |