Chapter 6. Style Sheets
Last chapter, you learned XHTML’s dirty little secret—it doesn’t have much formatting muscle. If you want your Web pages to look sharp, you need to add style sheets into the mix.
A style sheet is a document filled with formatting rules. Browsers read these rules and apply them when they display Web pages. For example, a style sheet rule might say, “Make all the headings on this site bold and fuchsia, and draw a box around each one.”
There are several reasons why you want to put formatting instructions in a style sheet instead of embedding them in a Web page. The most obvious is reuse. For example, thanks to style sheets, you can create a single rule to format level-3 headings, and every level-3 heading on every Web page on your site will reflect that rule. The second reason is that style sheets help you write tidy, readable, and manageable XHTML files. Because style sheets handle all your site’s formatting, your XHTML document doesn’t need to. All it needs to do is organize your pages into logical sections. (For a recap of the difference between structuring and formatting a Web page, refer to Logical Structure vs. Physical Formatting.) And finally, style sheets give you more extensive formatting choices than those in XHTML alone. Using style sheets, you can control colors, borders, margins, alignment, and (to a limited degree) fonts.
You’ll use style sheets throughout this book. In this chapter, you’ll learn the basics of style sheets, and see how you can use ...
Get Creating a Web Site: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.