CSS implementation in this version of Macromedia Dreamweaver is to advanced CSS developers what the previous version provided to beginners. Thankfully, CSS beginners have not been left behind. In this article, I'll take you through all the new CSS features, tools, and user interface changes in Dreamweaver 8. I've provided some sample files to help demonstrate what I cover in this article. Take a moment to download the sample files below, unzip them, and open the csstest.htm file in Dreamweaver 8.
To complete this tutorial you will need to install the following software and files:
Dreamweaver 8 retains much of the CSS-specific user interface elements introduced in Dreamweaver MX 2004. In fact, the MX 2004 interface choices are so important to this version's workflow that I am including a section specifically describing the interface elements that remain the same. The changes in this version build off the existing interface, incorporating enhancements intended to streamline user workflow.
The Property inspector sees only one change: the introduction of the CSS/Edit CSS button. This button gives the developer quick access to the pertinent definition in the CSS Styles panel. If the CSS Styles panel is already open, the CSS button is dimmed. The screen shot illustrates that I selected a paragraph <P> tag that had been styled, but since the CSS Styles panel was already open to that style, the CSS button is disabled.
Figure 1. The Property inspector in Dreamweaver 8 with the CSS button dimmed because the CSS Styles panel is already open to the selected style
The CSS Styles panel has seen some interesting changes, and these changes will be of special interest to developers who use an external CSS editor.
The first change is very subtle: The panel grouping, which includes the CSS Styles panel and the Layers panel, is called CSS. As shown in Figure 2, this change is very subtle, but will improve a user's ability to find the pertinent panel group quickly.
Figure 2. The panel group has been renamed CSS to improve usability
Note: When you collapse the CSS panel group as shown in Figure 2, clicking the CSS button in the Property inspector will open the CSS Styles panel. So, users should always be able to find this panel group.
Once the CSS Styles panel is open, the changes for Dreamweaver 8 become much more evident, and users face possible confusion.
The CSS Styles panel has two modes: All and Current. I actually find this nomenclature confusing, although it may only be confusing because it is so simple. The All mode displays a listing of declarations affecting the entire page—essentially “all” of the declarations. The Current mode displays the CSS declarations affecting the current element. See? There is no reason for confusion!
While in Current mode, the CSS Styles panel includes the following displays: Summary for Selection, Rules, and Properties. Figure 3 illustrates what I see with my insertion point in a paragraph that has been redefined to display blue in Geneva, 12 pixels.
Figure 3. The CSS Styles panel in Current mode with the insertion point in a paragraph that has been redefined to display blue in Geneva, 12 pixels
The Summary category lists only those attributes affecting the appearance of the selection (in this case, the paragraph currently selected). If I click within another paragraph assigned a class style called hilite_text, the summary category in the CSS Styles panel shows the new color defined by that class style (#99FF66) as shown in Figure 4 rather than the color defined by the redefinition of the paragraph tag (#0000FF).
Figure 4. The Summary, Rules and Properties categories of the CSS Styles panel showing info for the hilite_text style class
The Rules category displays the cascade of rules affecting the current selection. Refer to Figure 4 for an illustration of this. In Figure 4, the first in the cascade is the styling defined in the body tag. The attributes defined in that rule are contradicted by rules “closer” to the selection, so those attributes are not displayed in the summary section. In CSS terms, this “closeness” is known as specificity. You can learn more about specificity on the W3C site. The attributes set by the redefinition of the paragraph tag are next in the cascade, but only the font-family and font-size attributes affect the current selection. The final rule is the hilite_text class style, which only defines the color of the text.
There's a nifty alternate display, available by clicking the inner button in the Rules section. This About category displays useful information about the currently selected property, as shown in Figure 5. The property selected is the color property, as the About category heading indicates. The About category indicates which rule houses the specific property, and where that rule is defined.
Figure 5. The About category in the Current mode showing which rule houses the specific property, and where that rule is defined
That brings me to the Properties category of the CSS Styles panel. Click any property in the Summary category or click a rule in the Rules category, and the properties defined in the corresponding rule will display in the Properties category. The Properties category will also indicate which properties are affecting the selection: any properties that contradict and that are further up the cascade ladder will show a line through the property name. Try this by selecting the word “highlighted” on the first line of the csstest.htm file and then select the <body> tag in the Rules category. You will notice in the Properties category that font-family and font-size both have lines through them because the properties defined for font-family and font size in the <body> tag are contradicted by the properties for font-family and font-size defined in the <p> tag. Properties in the <p> tag override rules in the <body> tag because they are “closer” to the highlight selection.
Note: You will create the csstest.html file later in this article, but you can follow along with the csstest.html file in the sample files for now.
The Properties category is something of the meat-and-potatoes of the panel. Not only can you edit the details of any property already defined (for example, changing the color property defined in .hilite_text from #99FF66 to another color is as simple as clicking the color box or typing a new color), you can also add a property to that rule. Clicking the Add Property link provides a different-to-Dreamweaver method of defining CSS styles, but I will detail that in the User Workflow section.
The All mode of the CSS Styles panel shows all of the rules available to the page, whether those rules are defined within the head of the page or in a separate style sheet linked or imported from the page. As illustrated by Figure 6, the rules are separated according to where they are defined: rules defined within the head of the document appear under <style> while rules defined in a style sheet appear under the style sheet name.
Note: Inline styles—styles defined within the tag itself—do not appear in the All mode, but they do appear when appropriate in the Current mode.
Figure 6. The CSS Styles panel in All mode showing rules separated according to where they are defined
In addition to the listing of rules in the All Rules category, there is also a Properties sheet that performs the same as the one in Current mode. This mode seems familiar to the CSS Styles panel in Dreamweaver MX 2004, in that it displays and organizes the rules available to the page. The difference (a very welcome one) is that the Properties sheet allows you to see the properties of any selected rule, change any property, and add a property to the rule. Gone are the days of wishing the panel was 500 pixels wide to see all the properties!
The Properties sheet deserves its own section because it is so powerful. As I have mentioned, it is available for both All and Current modes. Astute Dreamweaver MX 2004 users will notice the similarities between it and the Relevant CSS panel (which it replaces). The power and flexibility of this user interface element will gradually sink in as you use Dreamweaver 8, and I will spend more time talking about how to use it in a workflow. For now, though, let me point out the buttons in the lower left corner.
Figure 7. The right button of the properties sheet shows only the properties that are set in the current document rather than all properties that can be set
For the screen shots I have provided in this section, I have selected the right button, which shows only the set properties. The other two buttons show all of the properties that CAN be set, listing them as grouped by category (left button) or listed alphabetically (middle button).
In the next section, I will review all the new features for visual display of CSS within Dreamweaver 8.
In this section, you can find all of the changes that will make advanced CSS developers weep with joy. There are new tools to help you see styles display as well as improvements in the style properties Dreamweaver renders.
The first group of display choices allow you to view or create a page that has different style sheets supporting different media types. You can select View > Style Rendering, and then choose a different media type to design or test the styles. In case you are wondering (and I know some of you are!), the easiest way to integrate multiple media types in a website is to define a separate style sheet for print media. The macromedia.com website makes use of a separate print media style sheet.
Figure 8. The Style Rendering menu showing the possible media types
A handy easy-to-overlook option is the last one: Display Styles. This option is enabled by default, but deselecting it removes all CSS rendering. This is useful as a sanity check for those of you who are concerned about accessibility. For example, reviewing the page without CSS rendering can help a developer see the order of content as a screen reader might encounter it.
The other group of display choices is available from the Document Toolbar. Clicking the visual aids button (the funny-looking eye) presents the following submenu.
Figure 9. The Visual Aids menu in the document toolbar
These choices will be most useful for users defining properties that include box properties and outlines. For each of the explanations below, I include a screen shot of exactly the same page. Each screen shot shows how the page is displayed with only the described display option enabled. The screen shot includes a DIV tag defined with positioning, padding, and margins; a DIV tag used only to house a P tag, and a P tag.
Note: The color of the layout backgrounds may not match those in Figure 10, and the background colors will change if you turn the feature on and off. There are a total of 16 colors that Dreamweaver can assign to the background colors. If you have more than 16 DIV tags on a page and some are nested, the overlapping background colors may be the same color. Turning this feature off and back on will help you work around this.
Figure 10. Styles shown with the CSS Layout Backgrounds visual aid enabled
CSS Layout Box Model: This choice adds some crosshatching to the inside and outside of a selected box element, representing any padding and margin settings. You will need to select the dotted border in the csstest.htm sample file for it to display as shown in Figure 11. Also, once the element is selected, there is a tooltip that will appear depending on where within the element you hover. In the screen shot below, I was hovering over the outline of the selected DIV tag. If I hover over the outer crosshatch, the tooltip indicates only the margin settings. If I hover over the inner crosshatch, the tooltip indicates only the padding settings. If I hover over the inside of the content, the tooltip indicates settings such as width and height.
Figure 11. Styles shown with the CSS Layout Box Model visual aid enabled
CSS Layout Outlines: This option adds an outline to any DIV tags. If nothing else, this is useful to help a developer select the DIV tag, but it is a handy way of seeing which elements are controlled by DIV tags. For example, in the screen shot below, it is simple to see that the last paragraph on the page is not in a DIV tag, but the one above it is.
Figure 12. Styles shown with the CSS Layout Outlines visual aid enabled
Layer Outlines: This option adds an outline only to DIV tags that are defined with box model properties. In other words, it outlines those DIV tags that are used for positioning purposes. This is illustrated in the screen shot below (remember the middle paragraph is contained in a DIV tag, yet that tag is not bordered). The top box still retains its highlighted border.
Figure 13. Styles shown with the Layer Outlines visual aid enabled
Dreamweaver 8 does an admirable job of rendering CSS elements, including at least one of the elements shown in the previous screen shots. Previously, box elements defined with a border of any kind displayed with a single line. Dreamweaver 8 now displays all border types, including the dashed line illustrated in the screen shots.
The most apparent improvements are how Dreamweaver renders various positional elements, especially those in complex pages and with nested tags. The following is a sampling of the rendering improvements:
I am cheerful that the interface in this version retains so many of the improvements introduced in the previous version. Since these remnants will continue to be important for user workflow, I am listing them here. Readers who are upgrading (and who are familiar with CSS in Dreamweaver MX 2004) can jump ahead. New users will benefit from this overview and from any of the Dreamweaver Developer Center articles on CSS written for Dreamweaver MX 2004.
The following interface elements are the same in Dreamweaver 8 as in Dreamweaver MX 2004:
The Page Properties dialog box is an important starting point for users creating a page. In this dialog box, you assign settings that will affect the appearance of the entire page. As of Dreamweaver MX 2004 and continuing in this version, some of these settings are designated with CSS style declarations. By the way, assigning CSS properties using the Page Properties dialog box writes the code for the properties to the head of the HTML document, even if the document links to an external style sheet. That is fine for now; I show you how to migrate the style declarations to an external style sheet in the “Moving from Document Style to External Style Sheet” section later in this article.
I have detailed a host of changes to the CSS Styles panel above, but some things have remained the same. The All mode of the CSS Styles panel will seem very similar to the behavior of the CSS Styles panel in Dreamweaver MX 2004.
In the next section, I will take you through some mini-workflow recommendations for the new CSS features in Dreamweaver 8.
In preparation for writing this article, I revisited the article I wrote for Dreamweaver MX 2004. With a certain amount of chagrin, I realized that I had not been following many of the workflow steps I suggested over these past months.
In the short time I have been using Dreamweaver 8, on the other hand, I have already changed my ways. In short, the user interface changes in this version better support a similar workflow. Most importantly, though, I don't intend to provide a single workflow. Follow the steps provided to test various workflows, but choose the one or ones that work best for you.
You will use this same site to house the files you create in the following workflows. This is also the same site I used in my CSS article for the previous version of Dreamweaver. So, if you diligently followed my previous article, use the same site. The file names for this article are different (so everything will live happily together).
Now that you have your site defined, I will guide you through the workflows in the next few pages.
This may be how some developers accidentally use Dreamweaver 8 at first. Although the style attributes you can define within the Property inspector are limited, it is easy enough to add attributes to existing selectors. And, let’s face it: it sure is handy.
Specify the following settings:
TD and TH tags are included with the body tag to receive the appearance stylings).In the following scenarios, I intend to show you different ways to quickly define simple properties.
<p.style1>.hilite_text in the New Name text field. <p.hilite_text> in the Tag Selector. The previous steps succeeded in creating a class style. Class styles, which are the only styles you will see listed in the Property inspector's Style pop-up menu, are style rules that you can apply to any tag. The next set of instructions explain how to redefine a tag.
hilite_text class style. In the New CSS Rule dialog box, select the Tag option from the Selector Types. Then choose P from the pop-up menu of tags. Leave the Define in choice to This document only.
Figure 14. The New CSS Rule dialog box
In the CSS Rule definition for P dialog box, specify the following settings:
This particular workflow takes advantage of a new menu command that I have not otherwise described.
Select Insert > Layout Objects > Div Tag.
Figure 15. The Insert Div Tag dialog box
Until you click OK, the DIV tag will not be written to the code of the page.
These simple workflow recommendations can help you get started, but you may be left wondering how these rules all work together. Let's use Dreamweaver to find out.
I have described the new user interface features available in Dreamweaver 8, but let's use these features to explore what you have created.
Organize the sections of the CSS Styles panel like the screen shot below. In particular, the contents of the Rules category may not be visible until you drag the Properties category down in the panel group.
Figure 16. Using the Current mode to explore the rules you have created
.hilite_text class rule. Yet the display in the Summary section makes no note of those differences. The section merely describes which properties affect the place where your cursor is placed. Click each line in the Summary section to see how the display in the Rules and Properties sections change. .hilite_text class rule. Click the Show Information button in the top right corner to see how the About category works. Now that you are comfortable with the information you can get in the CSS Styles panel, let's actually use the panel itself to create some style properties.
Using the CSS Styles panel to create or edit properties is a flexible workflow, but one that may be comfortable only for developers accustomed to other CSS editors. Unfortunately for them, they will not be able to create new rules using only the new user interface. But let's investigate what you can do.
That was fairly simple. Now you will create a rule and edit its properties.
Define the following settings:
<p> icon in the tag selector. .offset_text rule selected in the All Rules section, click the Add Property link in the Properties section. So far, you have been creating your styles in both the HTML document and in an external style sheet. In most cases, you want to keep all your styles in one place, and that one place is the external style sheet. In the next section, I will show you how to migrate the styles from the document into the external style sheet.
Some of the nicest workflow features—such as using the Page Properties dialog box to define CSS style properties—still write the rules to the head of the existing document. In most cases, you will want to move those rules into an external style sheet. There are two approaches available to do this. The first option is to export any existing styles into a new external style sheet. The second option is to copy the style code into an existing external style sheet. If you have an existing external style sheet, you should copy the code into it manually using the second option I outline below. Don’t try to export into an existing style sheet, or you will overwrite the CSS code that is already in it.
In the Export Styles as CSS File dialog box, save what will be a CSS file as test2.css.
Note: The file name cannot be test.css because exporting CSS styles creates a new CSS file with the rules defined in the HTML document, replacing any CSS file with the same name. Any rules defined in the original CSS file would be lost.
<style> and the existing styles may or may not be visible indented underneath. This listing includes all of the styles included in the internal style sheet. Select <style> in the CSS Styles panel and click the Delete CSS Style icon in the bottom right of the panel (it looks like a trash can). Although the page suddenly looks ugly—and the style code has been removed from the head of csstestexport.htm—the class attributes are still written to the code where those classes were assigned. <style>, although you also still have the test.css style sheet. Note: If you followed the steps in option 1 above, the code will have already been moved to an external style sheet. So when you get to step four below, you won’t see the code to be copied. If you want to follow the steps below, try undoing a few times in Dreamweaver (Edit > Undo) to get the code back into the head of the csstest.htm file. Then, use the steps below to copy the CSS code into the existing external style sheet.
p {
font-family: Geneva, Arial, Helvetica, sans-serif;
color: #0000FF;
}
.hilite_text {
color: #003300;
background-color: #FFFF66;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #333333;
}
.layer1 {
border: medium dashed #000000;
margin: 10px;
width: 250px;
padding: 10px;
position: relative;
left: 50px;
}
5. Switch to test.css and paste this code below the existing code.
6. Save test.css and close.
7. In csstest.htm, remove the remaining style tag code:
<style type=“text/css”>
</style>
After using both workflows for migrating CSS rules from a document to an external style sheet, notice the test.css has all of the rules, and test2.css has all but one of the rules. In development, avoid this by using only one of the above workflows, then attaching external style sheets to new documents as you create them.
You have used the new UI elements in Dreamweaver 8 to create styles... and to figure out what you have created. You have also investigated some of the new display capabilities for style properties.
Now that you are familiar with the CSS tools and features in Dreamweaver 8, I recommend that you read Adrian Senior’s six-part tutorial on designing with CSS in Dreamweaver 8. Even if you have been through the Dreamweaver MX 2004 version of the article series, I recommend that you go through it again. They have been completely updated for Dreamweaver 8 and will help you get into good CSS workflow habits.
Julie Hallstrom is a designer who hand-codes websites for small companies. She increasingly appreciates how Dreamweaver allows developers to quickly create a website with code as lean as hand-coding (or darned near).