Making Good-Looking Pages
"Hey, I know what to do," Claude said, taking back control from Anita. "You just use the toolbar buttons to change fonts and colors, just like in a word processor." Claude showed us what he meant by selecting a heading and clicking buttons on the toolbar to make the text larger and center it on the page."You're right, Claude," I said, "that's the simplest way to do things. But it's not the best way.""Why not?" he wondered."Because you're not letting the browser do the work for you," I explained. "Why change the font size and color for each and every heading? The browser knows it's a heading, so tell the browser how you want the headings displayed and let it worry about the details.""Huh," he said, "I guess that makes sense. Makes it easier to change your mind, too, right?""Exactly!" I answered, glad he understood it. "You tell the browser once how to display all the page elements used by your site. If you don't like something, you just change it in one placethere's no need to edit every single page.""Those are the styles you mentioned before," Stef said. "Like Word's styles.""Very much like those," I agreed, "except that Word styles define structure and presentation rules. In a Web page, the two concepts are separate: The page elementsthe tagsdefine the structure, and the styles define how to present that structure. Let me show you what I mean."
Defining Your Own Styles
"As you might already guess," I said as I took control of the computer again, "your browser comes with a set of predefined styles for displaying page elements. You can usually change these styles to suit your own needs, such as making the default fonts larger or using different colors for links. As a Web page designer, however, you can define new styles to control how your pages look in the browser. In most cases, your styles take precedence.""But visitors can always force the browser to use their preferences, right?" Anita asked. CSS Ideas
The site [http://cssvault.com/] showcases many Web sites that make creative use of cascading style sheets. It's a good place to check for design ideas."Right," I said. "You're not in total control. If visitors can't read your site because the fonts are too small, they're not going to care how much work you put into the design. They'll make the text bigger so they can read it. That's only fair. But only a very small percentage of your visitors will do that. Most will use the styles you define and see the site the way you meant it to be seen.""Hey!" Stef said, "can you use the styles to control how a page is printed?""Yes, you can," I answered. "Why do you ask?""Because sometimes when I print a Web page it doesn't look at all like what it does on the screen," she explained."That's the other advantage to using styles," I said. "You can define different rules for displaying the page versus printing the page." Turning to the monitor, I opened Nvu's Tools menu and selected the CSS Editor menu item. "Since styles are different from page elements, you use a different editor to create them. This editor is called a CSS editor. CSS stands for cascading style sheets, which is the geek term for a set of Web-page styles." There was a new window on the screen titled "CSS Stylesheets" (Figure 6.16). "This editor makes it all pretty simple, so don't get caught up with the terminology."
Figure 6.16. Nvu's style editor.
Figure 6.17. Creating a new style rule.
[View full size image]

Not all colors look the same in every browser. For an explanation of "browser-safe colors," examples of color charts, and more info on Web color, see [www.websitetips.com/color/].Claude typed "green" into the field. "Hey! It worked! Look at the heading!" He moved the editor window aside so we could see that the heading had indeed changed to green."Click the button next to the color field," I suggested. He did, and a color picker popped up (Figure 6.18). "If you can't name the color you want, just pick it here to create a special code for it."
Figure 6.18. The color picker.

Figure 6.19. Setting text-related properties.
[View full size image]

Figure 6.20. Creating a named style.
[View full size image]

Figure 6.21. Adding a div tag to the page body.
[View full size image]

Figure 6.22. The ning my head. "We've only fixed one page. The about page is still the same."
[View full size image]

Sharing Styles across Pages
"Not quite," I said, shaking my head. "We've only fixed one page. The about page is still the same.""So you need to copy the styles to it as well," Anita said."Yes, but there's an easier way to do it. Right now the styles we added to the home page are actually commands in the Web page. This is called an embedded or internal style sheet. We need to move them to a separate file, an external style sheet. Then multiple pages can link to it and share the style definitions.""So the pages will all look the same," Stef concluded."Right," I agreed, "and if you want to change things across all pages, there's only one place to go." Turning back to the screen, I brought up the CSS editor again. "Luckily, Nvu makes it really easy to switch from an internal style sheet to an external style sheet. On the left-hand side of the window, click the internal stylesheet button, then click the button on the right-hand side called 'Export stylesheet and switch to exported version.'" The button was rather lengthy and hard to miss (
Figure 6.23. Switching to an external style sheet.
[View full size image]

Figure 6.24. Changing the link tag.
[View full size image]

Figure 6.25. The style sheet is published with the page.

Figure 6.26. The style sheet applied to the about page.
