How to create document-level Cascading Style Sheets
This TechNote offers instructions on creating and changing the various types of styles which can be found in Cascading Style Sheets (CSS). For an introduction to the concepts behind CSS styles, consult An Overview of Cascading Style Sheets (TechNote tn_15320).
CSS styles, which provide pre-designated formatting to control the appearance of Web page content, can be located at the document level (in the HTML page itself) or in an external style sheet. This TechNote offers in-depth instructions on adding styles at the document level. See How to create an external Cascading Style Sheet (TechNote tn_12922) to create external style sheets.
Document-level style sheets
When you choose to make a style, you have several options for the type of style it will be: Custom Style (class), redefined HTML tag, or CSS Selector. Making each of the following examples of style types will acquaint you with the functionality of CSS styles in general and the purpose and use of each type of style in particular.
Note: For information on specific style settings (Type, Background, Block, Box, Border, List, Positioning, Extensions) for Web elements, choose Help > Using Dreamweaver> Inserting and Formatting Text > Using CSS Style Sheets > Creating a CSS Style in Dreamweaver. This sections provides a detailed description of each of the style settings and the many options.
Adding a Custom Style (class)
- Click the New Style button at the bottom of the CSS Styles panel (choose Windows > CSS Styles to open this panel). See Example 1 for Dreamweaver 4 and later versions to view the buttons at the bottom of the CSS Styles panel.
- Not necessary for Dreamweaver 3 users: In the New Style dialog box, select This Document Only from the Define in options.
- Select Make Custom Style (class) under Type.
- After selecting this type of style, type the name of your custom style ( Example 2). For this example, type the name
.inset. - Click OK.
- The Style Definition dialog box appears ( Example 3).
- Define your style. To follow the above example make the following choices for Type:
- Font: Times New Roman, Times, serif
- Size: 12 points
- Style: italic
- Line Height: 2 ems
- Weight: bold
- Color: #0000FF (blue)
- Click OK. Because the type of style chosen was custom, the name of the style will now appear on the CSS Styles panel.
- To apply this custom style to text on a Web page:
- Select text or a range of text.
Note: You can place the insertion point in a paragraph to apply the style to the entire paragraph or you can specify a tag to which the CSS should be applied by selecting the<p>tag with the tag selector at the bottom left of the Document window. - Click the style name in the CSS styles menu.
- Select text or a range of text.
Adding a redefined HTML Tag style
- Click the New Style button at the bottom of the CSS Styles panel (choose Windows > CSS Styles to open this panel). See Example 1 for Dreamweaver 4 and later versions to view the buttons at the bottom of the CSS Styles panel.
- Not necessary for Dreamweaver 3 users: In the New Style dialog box, select This Document Only from the Define in options.
- Select Redefine HTML Tag under Type.
- Choose an HTML tag to redefine by clicking in the tag pop-up list. To follow the example in these instructions, choose the h1 tag in the list of HTML tags (see Example 5 for Dreamweaver 4).
- Click OK.
- The Style Definition dialog box appears.
- Define your style. To follow the above example, choose the Color #00FF00 (green) for Background Color in the Background style definitions.
- Click OK. The new HTML Tag-type style will not be listed on the Custom Styles panel.
- To apply this redefined HTML tag style to a block of text on a Web page:
- Select a block of text.
Note: You can place the insertion point in a paragraph to apply the style to the entire paragraph or you can specify a tag to which the CSS should be applied by selecting the tag with the tag selector at the bottom left of the Document window. - Choose Heading1 in the Format pop-up list on the Property inspector.
- Select a block of text.
Adding a CSS Selector style
- Click the New Style button at the bottom of the CSS Styles panel (choose Windows > CSS Styles to open this panel). See Example 1 for Dreamweaver 4 and later versions to view the buttons at the bottom of the CSS Styles panel.
- Not necessary for Dreamweaver 3 users: In the New Style dialog box, select This Document Only from the Define in options.
- Select Use CSS Selector under Type. This choice allows you to:
- create a selector for a style which will affect elements in one tag only when those elements are nested inside of another tag (known as a contextual selector), or
- create an ID Selector, which redefines the formatting for all tags containing that ID attribute.
Note: You can also choose what is called a "pseudo-class" for the states of a link by clicking on the down-facing triangle on the Selector text box. [To eliminate the underline in links, see How to remove the underline from linked text (TechNote tn_14088).]
For this example, you will use a CSS Selector to modify text, but only when the text is inside of a table cell. - In the Selector text box, type two HTML tags with a space in between them. Or, to follow this example, type the following:
td p
Note: On the Macintosh you will have to select and delete a:hover in the text box before typing in thetd p. Also note that not all combinations of tags will render as you might expect in different browsers. Test all CSS selector combinations in different browsers on different operating systems to see if the style renders consistently. - Click OK.
- The Style Definition dialog box appears.
- Define your style. To follow the above example, enter the following settings in the Type style section:
- Font: Courier New, Courier, mono
- Size: medium
- Style: normal
- Weight: bold
- Color: #FF0000 (red)
- Click OK. The new CSS Selector style will not be listed on the Custom Styles panel.
- To apply this CSS Selector style to text in a table cell:
- Select text in a table cell.
Note: You can place the insertion point in a paragraph to apply the style to the entire paragraph or you can specify a tag to which the CSS should be applied by selecting the tag with the tag selector at the bottom left of the Document window. - Choose Paragraph in the Format pop-up list on the Properties inspector.
- Select text in a table cell.
Changing a document-level style
- Choose Text > CSS Styles > Edit Style Sheet. Or, click the Edit Style Sheet (in Dreamweaver 3, the Open Style Sheet) button at the bottom of the CSS Styles panel (choose Windows > CSS Styles to open this panel).
- Select the style you want to change in the Edit Style Sheet dialog box.
- Click Edit.
- The Style Definition dialog box appears.
- Change your style definitions.
- Click OK.
- Click Done on the Edit Style Sheet dialog box. Web page elements to which the style has been applied will update automatically.
Additional Information
For more information on CSS, consult these Macromedia articles and TechNotes:
- Using Cascading Style Sheets
- Creating different CSS style sheets for different platforms
- Turning off link underlining
- Removing CSS Classes from a Dreamweaver page (TechNote tn_15119)
- How to remove the underline from linked text (TechNote tn_14088)
- How Can I update HTML styles? (TechNote tn_14245)
The Inserting and Formatting Text sections of Using Dreamweaver and Dreamweaver Help provide additional material on the subject of CSS. See also W3C's recommendations for CSS, as well as an excellent listing of resources devoted to CSS, the W3C's Cascading Style Sheets home page.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
