Home > Articles

Cascading Style Sheets

  • Print
  • + Share This
This chapter is from the book

Editing CSS in Code View

Dreamweaver MX 2004 provides handy option menus for setting a wide variety of CSS styles, but these menus don't cover everything you can do with style sheets. To get the most out of your CSS styles—or to edit someone else's style sheet—you will eventually need to work with CSS in code view.

In code view, you're working directly with the CSS language, writing the selector, the braces, and the declarations instead of letting Dreamweaver MX 2004 do it for you. The code view for CSS is shown in Figure 10.11.

Figure 10.11Figure 10.11 Editing a style sheet in code view lets you directly manipulate CSS rules.

To enter code view, you need to open a style sheet via the Open option on the File menu or create a blank style sheet with the New option from the File menu. Then you'll see the raw CSS codes displayed for you, ready to be edited. Save the file via the Save option on the File menu when you're done with it.

Starting with Dreamweaver MX 2004 Style Sheets

To make it easier to use CSS styles, Dreamweaver MX 2004 comes with a selection of standard style sheets that can be used as the basis of your own style sheets. Using these style sheets is easy: choose New from the File menu and select from the available style sheets. The style sheet you pick will open in code view in Dreamweaver MX 2004, and you can edit and save your modified style sheet.

The list of Dreamweaver MX 2004 style sheets is shown in Table 10.12. Most of these style sheets also define class styles that you can use in your designs along with any custom class styles you create.

Table 10.12 Dreamweaver MX 2004 Style Sheets

Style Sheet Name


Basic: Arial

Sets the text (body, th, and td) to Arial font; defines no class styles.

Basic: Times

Sets the text (body, th, and td) to Times New Roman font; defines no class styles.

Basic: Verdana

Sets the text (body, th, and td) to Verdana font; defines no class styles.

Colors: Blue

Selects a blue color scheme; defines no class styles.

Colors: Blue/Gray/Purple

Selects a blue, gray, and purple color scheme; defines no class styles.

Colors: Blue/White/Yellow

Selects a blue, white, and yellow color scheme; defines no class styles.

Colors: Red

Selects a red-on-black color scheme; defines no class styles.

Colors: Tan/Brown

Selects a tan and brown color scheme; defines no class styles.

Colors: Yellow/Brown

Selects a yellow and brown color scheme; defines no class styles.

Forms: Accessible

Sets the text (body, th, td, and form controls) to Arial font, using relative units.

Forms: Arial

Sets the text (body, th, td, and form controls) to Arial font, using absolute units.

Forms: Times

Sets the text (body, th, td, and form controls) to Times New Roman font, using absolute units.

Forms: Verdana

Sets the text (body, th, td, and form controls) to Verdana font, using absolute units.

Full Design: Accessible

Defines a complete page style in Arial font set using relative units; colors are blue, green, and gray.

Full Design: Arial, Blue/Green/Gray

Defines a complete page style in Arial font set using absolute units.

Full Design: Georgia, Red/Yellow

Defines a complete page style in Georgia font set using absolute units.

Full Design: Verdana, Yellow/Green

Defines a complete page style in Verdana font set using absolute units.

Link Effects

Creates special effects around links.

Text: Accessible

Sets the text (body, th, and td) to Times New Roman font, using relative units.

Text: Arial

Sets the text (body, th, and td) to Arial font, using absolute units.

Text: Times

Sets the text (body, th, and td) to Times New Roman font, using absolute units.

Text: Verdana

Sets the text (body, th, and td) to Verdana font, using absolute units.

The style sheets identified as Accessible are created with relative units and thus are made to conform to the user's font requirements instead of overriding them with absolute font sizes.

The complete list of class styles defined in Dreamweaver MX 2004 style sheets is shown in Table 10.13, as well as the style sheet in which they're available. These classes correspond to the most common types of Web design tasks you'll encounter when using CSS.

Table 10.13 Predefined Class Styles in Dreamweaver MX 2004 Style Sheets

Class Style

Style Sheet



Forms, Text

Small text size



Medium text size


Forms, Text

Large text size



Extra-large text size


Forms, Text

The main text content's style



Text with spaced-out letters



Justified text


Forms, Full, Text

A box with a 3D border


Forms, Text

A box with a solid border



The title of the page



The subtitle of the page



The large text at the top of the page



The navigation bar's style



Each item of the navigation bar



A sidebar's style



The header of the sidebar



The footer of the sidebar


Full, Text

The page footer's style



Legal notices (the fine print)



Promotional text



The title bar





Link Effects

Invisible links


Link Effects

Navigation links


Link Effects

Menu links


Link Effects

Links with borders



A wide input field



A narrow input field

You can attach multiple style sheets to any HTML document, which means you may want to create several style sheets and combine them. To make a quick and easy design, you could create and save style sheets based on the Text: Times and the Color: Red sheets. You can see how this looks in Figure 10.12; it took less than a minute to create these styles.

Figure 10.12Figure 10.12 Using the Dreamweaver MX 2004 style sheet Text: Times and Color: Red as a base lets you start quickly.

Alternatively, a Full Design style sheet can be used as the basis for a more complex design. Figure 10.13 shows what a difference the style sheet can make on the appearance of a page.

Figure 10.13Figure 10.13 Choosing a different starting style sheet, such as Full Design: Georgia, produces a different effect with the same HTML.

Writing Advanced CSS

To use specialized CSS properties—which aren't covered in the CSS styles options in Dreamweaver MX 2004—you'll need to add them manually. Many of these properties are rather obscure and not often needed; for example, the cue-after property defines a sound to be played by an audio browser. The complete list of CSS properties is available via the Help panel in the O'Reilly CSS Reference.

Importance, Order, and the Cascade

As mentioned earlier in this chapter, the C in CSS stands for "cascading," and is a reference to the cascade. The cascade is the method for combining several styles, which may have conflicting notions as to the value of a CSS property. For example, three rules might specify the color of the text, and all three might conceivably be applicable. The cascade allows the browser to determine the "winner" for those parts of the styles that conflict; if there is no conflict, the styles can be combined and applied.

The general principle in the cascade is that the most specific style wins. Thus, if you have one style about body and another about h1, the h1 is going to be more specific, so the headline will follow the second style in the case of a conflict. A class style is considered more specific than a redefined HTML element, and an ID selector—one of the types of CSS selectors—is more specific than a class selector.

If two conflicting styles are equally specific—such as two rules about h1—the next rule is that the style declared later in the style sheet—the "newer" style—takes precedence. In our hypothetical case, both h1 styles would be applied to all first-level headings, and if there were conflicting styles—one setting the color blue and another setting it red—the second style would prevail for that property.

For this reason, order can be crucial for creating and perfecting CSS style sheets. Dreamweaver MX 2004 doesn't automatically move styles around for you, but in code view you can cut and paste styles to put them in the preferred order.

The cascade order can also be changed by the use of a special keyword, called !important. That's an exclamation point before the word important. Although this may appear to mean "not important" in the eyes of most programmers, in the CSS language it means "very important." The !important keyword placed after a property declaration jumps that declaration to the very front of the priority order. If there's a conflict, any style with !important after it will beat any style without it.

In Listing 10.4, you can see an example of a style sheet that was created to illustrate the cascade in action; notice how you can change that order by using !important.

Listing 10.4 The Cascade Will Be Used to Determine the Effects of These Conflicting Styles

p { 
  color: white !important; 
p { 
  color: violet; 
p {
  background-color: blue; 
p { 
  background-color: black; 
.person { 
  background-color: red; color: green;

In evaluating this style sheet, the browser gives highest priority to any !important styles. The first p style would ordinarily be superceded by the second p style on the issue of text color, but the first style has the magic keyword !important—so the color of the text is white.

The third p style loses out to the later-defined fourth p style for the background-color property, so the background color is black. For HTML tags that are set class="person", the .person style is more specific than the p tags, so the background-color will be red—except that the first p style is !important, so the text color will be white.

Figure 10.14 is a screenshot showing how the browsers use this logic to get the results described.

Figure 10.14Figure 10.14 The cascade order was used to determine the colors of the text and background.

CSS Comments

Nearly every computer language invented allows for the developer to insert comments, and CSS is no exception. A comment is embedded in the code and ignored by the browsers, but is available to the designer to read and edit. To create a comment in a style sheet, simply add a slash and an asterisk (/*) at the start of the comment, and end it with an asterisk and a slash (*/). Everything between the markers will be ignored by the browser.

Comments are most often used to provide internal documentation so that other designers who use your style sheet can understand it. They're also useful for avoiding those head-scratching moments when you ask yourself, "What was I thinking?" You can also use comments to prevent certain rules or properties from being applied, without deleting them entirely; this is useful for testing purposes.

As shown in Listing 10.5, comments can also be used for copyright and author information. In this listing, each class style is described; you don't have to do this, but it's good practice.

Listing 10.5 Comments Make This Style Sheet Easier to Read and Understand

 Style Sheet for the Idyll Mountain Internet staff page

 Copyright (c) 2002 by Kynn Bartlett <kynn@cssin24hours.com>

body { 
 /*Default font for the page*/
 font-family: Arial, sans-serif;

h1, h2, h3, h4, h5, h6 {
 /*Make the headers more distinct*/
 font-family: Verdana, sans-serif;
 color: teal;
p {
 /*This will add padding to all paragraphs...*/
 padding-left: 3em;
.person {
 /*...except for those where class="person"*/
 padding-left: 0em;
 font-size: large;
 font-weight: bold;
 color: maroon;
.job {
 /*Make the job title stand out*/
 font-weight: bold;

Inline Style Attributes

You can attach a style sheet to an HTML document with the <link> tag, or you can embed it within the <style> element. A third way to apply styles to HTML is by using inline style elements. An inline style element enables you to apply a style directly to a section of HTML without specifying it in the style sheet; this can be useful for quickly adding a style that appears in only one place on your site.

As shown in Listing 10.6, you set the attribute style to the declaration portion of a style rule. There's no need for a selector, because the selection is the content of the tag with the style attribute.

Listing 10.6 A Snippet of HTML Code That Uses an Inline Style Attribute

<p>Although <span style="color: red; font-weight: bold;">
 rarely seen around the office</span>, 
 <span class="job">Chief Technologist</span> 
 Kynn Bartlett does system administration as well as trailblazing new 
 technologies and leading our accessibility efforts.</p>

Inline styles are much less useful than attached or embedded styles, and for that reason, Dreamweaver MX 2004 doesn't support them. To add an inline style in Dreamweaver MX 2004, you need to edit the source code and add the attribute. You might need to use inline styles if you want to apply a specific style only once, but in general, it is easier to create a class style and store it in an attached or embedded style sheet.

Media-Specific Styles

The CSS specification enables you to designate style sheets that are used only by specific media types, which are broad categories of output devices. The default media type is screen, which assumes that your browser will be displaying the Web page on a monitor. The complete list of CSS media types is shown in Table 10.14.

Table 10.14 Media Types Defined by CSS

Media Type



Pages read out loud by synthesized voice; for example, screenreaders for the blind.


Content represented by raised dot characters on Braille terminals for blind users.


Pages printed out as raised dots in Braille, on thick paper.


Content displayed on a limited-size handheld screen.


Pages printed out on paper.


Content displayed as slides or transparencies projected on a large screen.


Pages displayed on a color monitor.


Content printed on teletype devices or other media with limited display capabilities, which print characters only of a fixed size and type.


Pages displayed on a television screen, possibly taking advantage of sound capabilities but with limited interaction.

To create a style sheet for a specific media type, such as print, create a new style sheet based on your original and change the style rules that don't apply to the new output device. For example, many printers are black and white, so color might not be as useful. In Listing 10.7, the print.css style sheet has replaced color properties with other style effects.

Listing 10.7 /*print.css

 Print Style Sheet for the Idyll Mountain Internet staff page

 Copyright (c) 2002 by Kynn Bartlett <kynn@cssin24hours.com>

body { 
 font-family: Arial, sans-serif;
 font-size: 12pt;
 /*An absolute font size has been set*/

h1, h2, h3, h4, h5, h6 {
 font-family: Verdana, sans-serif;
 text-decoration: underline; 
 /*Headers are underlined, and are not teal*/
p {
 padding-left: 3em;
.person {
 padding-left: 0em;
 font-size: large;
 font-weight: bold;
 border: 2px solid black;
 /*Names are in boxes, and are not maroon*/
.job {
 font-weight: bold;

To attach both this style sheet and the normal style sheet to the same HTML file—but have them apply to different media types—save them as different names and attach each to the HTML document. Then open the HTML document in code view and change the <link> tag. Add the media attribute to each <link>, as shown in Listing 10.8.

Listing 10.8 The Head of an HTML File That Attaches Two Style Sheets—One for Screen and One for Print

<title>Idyll Mountain Internet Employees</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="idyllmtn.css" rel="stylesheet" type="text/css"
<link href="print.css" rel="stylesheet" type="text/css"

When you load this Web page in your browser, one style will be displayed on the screen and a second will appear on your hard copy when you click Print.

Design Time Style Sheets

Dreamweaver MX 2004 enables you to specify style sheets that are displayed only while you are editing and that aren't included in the Web page when it's saved or previewed. These are called design time style sheets and are accessed through the CSS menu.

You create a design time style sheet the same way you create any other style sheet; however, because this is intended only for your eyes and no one else's, you don't need to worry about making it look pretty. The purpose is to make certain things stand out while you're editing, as shown by the styles in Listing 10.9.

Listing 10.9 This Style Sheet Highlights Acronyms, Abbreviations, Headers, and Two Class Styles


abbr, acronym { background-color: silver; } 
.person {
  background-color: #FFCCFF;
.job {
  background-color: #66FF66;
h1, h2, h3, h4, h5, h6 {
  border: thin dotted teal;

After you've saved your style sheet, you can apply it to your editing environment by choosing Design Time from the CSS menu. Add the style sheet by clicking the plus sign and browsing to find it. Dreamweaver MX 2004 will now display the HTML page using the styles you've defined in your design time style sheet.

Remember that these styles will not be shown in your browser, even when you preview the page; they are used by Dreamweaver MX 2004 only while you're in design view. Design time style sheets effectively enable you to extend Dreamweaver MX 2004's display capabilities to highlight whatever you like while editing!

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020