An external style sheet consists of a .css file containing code that defines styles for HTML elements and CSS classes. A CSS class is a named set of styles that can be applied to an HTML element by using the class attribute of the HTML tag.
For more information on CSS classes, see "Creating and Using CSS Classes," p. 401, in this chapter. FrontPage provides the ability to create external style sheets either from preexisting templates or from scratch. External style sheets based on a template are created using the More Page Templates link in the New task pane. You click the Style Sheets tab and select a style sheet template. FrontPage will provide a brief description of the formatting that the style sheet will provide, as seen in Figure 19.1. Figure 19.1. The Page Templates dialog box provides a brief description of each style sheet template.Interestingly enough, a preview is only provided for the Normal Style Sheet template that, because it is a blank style sheet, simply previews as a blank white page. However, you do get a general idea of how the style sheet will format a page from the description given.
If you choose a template other than the Normal Style Sheet template, you can modify any one of the styles provided or create your own styles to add to it. If none of the provided templates suit your needs, create your own style sheet from scratch by selecting the Normal Style Sheet template. For the most part, styles are applied to pages in the order in which they are encountered. For this reason, embedded style sheets are placed after the <link> tag (if present) that links to an external style sheet so that the embedded styles override the styles defined in the external style sheet. Inline styles override styles defined in an embedded or external style sheet because an inline style is applied directly to the HTML tag itself. Any style applied to a particular HTML tag also applies to any child tags of that tag. For example, if you format the <body> tag with a CSS style, that style will apply to the entire page unless it is overridden by another style. TIP Netscape 4 has a problem with applying styles from parent tags. If you are designing a page that is going to be viewed in Netscape 4, make sure to test carefully and apply the style to all necessary selectors individually. This process of cascading styles is how the term Cascading Style Sheets came about, but there are exceptions. Suppose, for example, you have a style in your external style sheet that formats the a selector and you don't want an embedded style sheet to override your style. You can add the ! important statement to the style in your external style sheet to give it priority over the style in the embedded style sheet. Your external style sheet style will then appear as follows: a { color: blue; text-decoration: none; ! important } If a page linking to the external style sheet also has an embedded style sheet that includes a style for the a selector, the style in the external style sheet will still take precedence because of the added weight given to it by the ! important statement. However, if the embedded style sheet also uses the ! important statement when defining the style for the a selector, it will override the style in the external style sheet. Creating an External Style SheetThe best way to understand external style sheets is to create a new style sheet and use it to experiment with formatting a page. FrontPage's default Frequently Asked Questions page is the ideal page to use for this purpose because it contains many HTML elements by default. To create a new Frequently Asked Questions page
Now you will need a new blank style sheet that will be used to format the CSSTest.htm page. Create a new style sheet.
The first thing you will likely notice is the Style toolbar (shown in Figure 19.2) that is floating in Design view. Using this toolbar, you can easily edit your style sheet. Click the Style button on the Style toolbar to display the Style dialog box as shown in Figure 19.3. Using the Style dialog box, you can easily start building your style sheet. Figure 19.2. The Style toolbar floats above your page when editing style sheets in FrontPage.Figure 19.3. The Style dialog box makes easy work out of creating style sheets.
In the left side of the Style dialog box is a list of some of the HTML tags to which a style can be applied. TIP You can change this list so that it contains only styles that you have defined by selecting the User-defined styles option in the List dropdown seen below the list of styles. The Style dialog box also includes a preview of your style sheet applied to a sample paragraph and sample characters. This preview is not precise, but it's a good estimation of how the style will look on your page. The Description box on the Style dialog box provides you with instructions on how to use the dialog box when no styles are defined for the selector that is selected in the Styles list. If a style is defined for the selector, the Description box will provide you with a rundown of the style's attributes as seen in Figure 19.4. Figure 19.4. The Description box provides an overview of the selected style.Three buttons on the Style dialog can be used to edit your style sheet. The New button allows you to create a new style for a selector that is not already listed in the Styles list. You can use this to create a new style for an unlisted HTML tag, or you can use it to define a new CSS class. (We'll cover CSS classes later in this chapter.) The Modify button allows you to modify styles that already appear in the Styles list, and the Delete button allows you to delete a style that was previously applied to a selector. Apply a style to the hyperlinks in CSSTest.htm as follows:
Your CSS file should now look similar to the file in Figure 19.7. Save the changes to the style sheet. Figure 19.7. This style sheet applies styles to hyperlinks.You might be wondering why you modified the a:hover pseudo-selector last instead of modifying them in the order in which they appear in the Styles list. The reason is that, as previously mentioned, styles cascade. The a:link pseudo-selector applies to all hyperlinks. Therefore, if the a:link pseudo-selector appears below the a:hover pseudo-selector, it will override the a:hover pseudo-selector. If you review the CSS code that FrontPage generated, you will see how straightforward CSS really is. The following CSS properties were set by the changes you made in the Modify Style dialog box:
Using these four CSS properties, you have transformed your hyperlinks from the boring defaults to interactive, customized hyperlinks. Applying an External Style Sheet to a Web PageBefore you add any more styles to the style sheet, now is a good time to apply the style sheet to the CSSTest.htm page. An external style sheet is applied to a Web page by linking it to the page using a <link> tag. FrontPage provides a convenient method for linking an external style sheet to a Web page.
You should see the changes to CSSTest.htm applied immediately in Design view. Switch to Preview view or preview the page in your browser and hover over the hyperlinks to see your styles in action. Adding More Styles to the Style SheetWhen modifying the hyperlink styles, you might have noticed that an a selector appeared in the Styles list in addition to the a:link, a:hover, a:visited, and a:active pseudo-selectors. The a selector represents any HTML <a> tag. In the CSSTest.htm file, there are several HTML bookmarks so that when a user clicks on a question in the FAQ list, it will take him to the correct spot in the file. HTML bookmarks are configured with <a> tags, but they aren't hyperlinks because they don't really link to anything. Therefore, these bookmarks are not affected by the selectors that you've already formatted. To affect the bookmarks, you will need to apply a style to the a selector:
Your style sheet should now resemble the page in Figure 19.9. Figure 19.9. Your style sheet now has formatting for all a selectors.You should now have a good idea of just how powerful CSS is. If you decide to reformat hyperlinks at a later time, changing their format is as easy as changing the CSS file. Without using an external style sheet, you would have to open each page and change it individually. If you were dealing with a site with hundreds of pages in it, formatting with CSS can make an otherwise arduous task quite easy. NOTE The Class and the ID dropdowns on the Style toolbar are disabled when modifying selectors that are HTML tags. These dropdowns will be used later when you learn about CSS classes. |