2 June 2008
Part 1 and Part 2 of this tutorial series.
Beginning
Note: This tutorial was written for Dreamweaver CS3. Although Dreamweaver CS4 adds new CSS functionality (revised Property inspector, Code inspector, related files), the CSS panel in Dreamweaver CS4 has not changed, and you should still be able to follow this tutorial using Dreamweaver CS4.
This three-part tutorial shows how to use Fireworks and Dreamweaver to design and build a fictitious blog named Blimey. Part 1 showed you how to prepare images in a Fireworks comp for the structural markup of the layout. In Part 2, you coded the markup that provides the hooks for the cascading style sheet.
This part of the tutorial shows you how to complete the layout and create the style sheet.
There are several ways to create an external style sheet in Dreamweaver. In this tutorial, you will use the Plus (+) button on the CSS Styles panel:
This procedure writes the first rule to an external style sheet and attaches it to the current page.
This rule may strike you as odd. If you are new to CSS layouts, you may not know that before you apply a single rule to your page, there is already a browser style sheet that affects its display. Many elements have default values; such as those you added to the group selector. These values vary from browser to browser and thus lead to differences in the layout when you add your own values. By zeroing out these elements, you give your layout a consistent starting place for the values in your own style sheet. Many developers reset many more elements, and sometimes include other properties such as borders set to none. To learn more about browser style sheets and how to reset them, you can read the following articles by Eric Meyer:
Note: If you need to edit a rule after you have closed its dialog box, simply select it and click the Edit Style button (the pencil icon) at the bottom of the CSS Styles panel. You can also edit properties and values directly in the Properties section of the CSS Styles panel.
The next rule you will write is for the body element:
Note: The settings in Figure 4 instruct the browser to display the text at 100% of whatever the user has set in the browser preferences. For example, someone with impaired vision may have changed the browser preferences from the default font size of 16 pixels to 18 pixels or higher. In later exercises, you will scale other text such as h1 and p from that user setting. By setting the body to 100% of the user's browser font size, all future font sizes will scale from that starting point. For example, if you later set the paragraph font size to 85%, it will be 85% of the user's font preference, whether that is 12, 14, 16, 18, or more pixels.
Before you style any of the div elements, or divs, in the various modules, you will style the container div that will be common to all of them. Because you will reuse the container four times, use the class selector type.
The width of the container is constrained to 770 pixels, and it is placed inside a div such as header whose background color band spans the entire width of the browser window.
The auto margins center the layout in modern browsers. Internet Explorer 5 does not understand this value. If you need to support that browser, you can learn how to center layouts for it in Do You Want To Do That With CSS? — Centering a Wrapper by John Gallant and Holly Bergevin. Alternatively, you may decide that there are not enough visitors who still use this very old browser to bother with coding for it. Those visitors will still see the content, although it will be on the left side of the browser window rather than centered.
The next rules you will tackle are those for the header div, which includes the background image, the navigation list, and the search form.
The first step is to add the background rules that give the header its band that stretches across the entire browser window:
Figure 8 shows what the header looks like at this point.
Note that the container within the header constrains the content to a fixed region
Within the header, you are going to write rules to float the navigation list to the left and the search form to the right. To learn more about placing content on opposite sides of a div, refer to Do You Want To Do That With CSS? — Align Elements Left and Right by John Gallant and Holly Bergevin.
The next step is to style the links in the unordered list. To make sure only links within the header div display as horizontal buttons, you need to use descendent selectors. Styles applied to HTML elements such as the ul are global in scope. That is, they apply to every instance of that element on the entire page. To make an HTML element more specific, you can style it within the context of a particular page area such as the header. Thus, a style for #header ul applies only to unordered lists in the header div of the page.
In the steps below, note also of the list-style type. This type removes the bullets from the list so the links look more like buttons.
The next rule changes the list items from block elements that each appear on a separate line to inline elements that flow side by side. Use the Block category in the CSS Rule Definition dialog box to access the display property:
To complete the header div, you need to finish the visual formatting of the link states, which are also known as pseudo selectors. Use group selectors to format two link states at the same time, and write descendent selectors to ensure that only links in the header div look this way:
To style the states of the links, follow these steps:
Do not assign widths to the floats.
The next steps float the search form on the opposite side of the header container and set the search icon image as a background that displays on the left side. The 25 pixels of padding carve out a space for the image.
The next rule, which is another descendent selector, positions the label text off-screen by using absolute positioning to take the element out of the normal document flow. Setting its top coordinate to –10000 moves it off the display area of browser windows.
The completed header should look like the image shown in Figure 12.
The second module, or mini-layout, includes the masthead logo, as well as a background gradient that spans the entire width of the window.
The rule for positioning the logo replacement text off-screen uses the same technique as the rule used to position the search label text off-screen.
This is where things get tricky. Many developers like to carve a large left or right margin for a content area and then float a sidebar in the empty space. One problem with this approach is that you can run up against something called the block formatting context.
You may think of divs as self-contained entities that interact with other areas of the page in completely controlled ways. However, the block formatting context can surprise you. A div by itself is not necessarily an independent object. If you have ever floated an image in the content area of a page and then added a clearing div under it, only to see the floated sidebar area get cleared as well, you know that divs are not always independent.
Figure 15 shows a left-floated image in the content area of the page. The second heading on the page is riding up into the image area. Most designers will add a clearing property to push it down under the image.
When you add a clearing property to a layout that has a floated sidebar, the clearing property for the image also clears the floated sidebar, as shown in Figure 16.
Because using floats is one way to establish a new block formatting context, styling all columns and their wrappers as floats is a great way to structure independent page areas. This technique works particularly well in a fixed-width layout like this one.
Note: Another benefit of using all floats for columns is that it prevents what's referred to as the Internet Explorer 6 three-pixel text-jog bug.
You can use the all-float technique described in the previous section to manipulate the divs in the page content module.
Use the following steps to float the secondary content div to the left and give it a width of 250 pixels. The Accordion widget will automatically reduce in width as well. Its default behavior is to take up the entire width of its parent container.
Next, create a rule to float the main-content div to the left and give it a width of 500 pixels. The div will have a left border to serve as a separator between the two columns. In order for this border to continue to the bottom of the content region, the main-content div must be longer. If you need to have short main-content pages, you will need to create a border image that you can place on the content-wrapper div that is the parent of both the secondary and main content divs. You may know this technique as faux columns.
This rule styles the h1 element so that it has a decorative background image.
#main-content div tag.<h1>.</h1> to close the h1 tag.
You are ready to tackle the final module, the footer. To reinforce the tutorial's lessons about floats, let's proceed in a slightly different way.
The footer itself spans the entire width of the browser window. Note that you are not floating this parent div like you did the header div.
Important: This property clears the floats in the content module. Without this property, the footer would display in odd ways.
The footer's border needs to go in a footer wrapper instead of with the columns so that the border continues no matter which column is longest. To give the illusion of equal height columns with borders that extend to the bottom, use the footer_bg.jpg image that you created in the Fireworks comp for this project.
The result probably surprises you unless you remember that you need to use a float clearing method to contain the floated divs within the footer. In the next step, you will use the clearfloat method that is popular with many developers.
The clearfloat class rule of the layout is for the br elements you placed in the code before Module 4 and after the closing div for the footer-wrapper and before the closing div for the container. The trick here is to remove anything that causes the break to have dimension:
This is the name you gave the class in the markup when you added the br clearing element.
To make the columns fit within the inner borders, create a rule that floats the three columns and gives them their width.
Note: In Dreamweaver, you will probably see a gray color behind the columns in Design view, although everything will display properly in the browser. Design view does not always render CSS styles perfectly. When in doubt, check the browser, and check as many of them as possible.
This last descendent selector formats the look of paragraphs in the columns. Add a line-height in the Type category to introduce some leading—the space between lines of text. In this instance, it's better not to use a standard unit of measurement because doing so can cause unexpected bugs in the layout. Instead, select Multiple from the Line Height pop-up menu.
There is a detail to take care of in the Tab 1 content area: the Blimey girl image sitting at the baseline of the first paragraph of text. Because images are inline elements, they follow the default behavior of such elements to flow one after the other. The image is taller than any letter, so it makes a large space in its row. Adding a float to the image enables the text to wrap around it.
One reason to use a class for this task instead of an ID is that you might want to add other images to the content region. Classes can be used multiple times while IDs must be unique on the page:
The text should now wrap around the image as shown in Figure 31.
In the heat of creation, you probably added rules in no particular order. This would be a good time to take a "cleansing breath" and bring a little order to the chaos. Dreamweaver CS3 lets you drag and drop rules right in the CSS panel. I like to order my styles according to their place in the source order. There are as many ordering preferences as there are developers, however.
As noted in Part 2 of this tutorial, Dreamweaver places dependent files that control the behavior of the Spry widgets in a SpryAssets folder. You can modify the appearance of the widgets by changing properties and values in their style sheets.
In the SpryAssets folder, locate the SpryAccordion.css file for the Accordion widget and open it. The file contains extensive comments that explain the purpose of each rule.
The steps part in this section use the Properties pane of the CSS panel extensively as a quick way to adjust existing properties or to add new ones.
Do not change anything in the .AccordionPanel rule. Skip over that one and move on to the next one, .AccordionPanelTab.
Do not make any changes to the next rule, .AccordionPanelContent; instead skip to the following rule: .AccordionPanelOpen .AccordionPanelTab.
The next rule governs the hover color of the Accordion menu text.
The next two steps apply to the following rules:
Next you will add four new rules to the Accordion style sheet to style the list of links in each Accordion panel.
Because these rules all start with the .AccordionPanelContent class, an easy way to begin creating them accurately is to click the rule name and copy it to the clipboard.
Figure 40 shows the completed Accordion widget.
The Tabbed Panel widget requires fewer style changes because it does not involve navigation. The first two rules are fine as they are; so start with the .TabbedPanelsTab rule:
Congratulations! The layout is now complete, and the client should be satisfied because you took a Fireworks comp and translated it quite precisely into code in Dreamweaver. There are still a few tasks, including checking for browser compatibility, that you might want to complete in the interest of thoroughness, however. Dreamweaver CS3 makes this easy with its new feature, the Check Browser Compatibility page check.
The goal for this layout is to keep hacks to a minimum. Indeed, if you were to do a page check, you would find that there are no serious issues.
What the results panel does not show, however, is that there are a few discrepancies in the appearance of the page when it is viewed with Internet Explorer 5. If you need to support the various version 5 upgrades of Internet Explorer, you can tweak the page with a centering fix (as described earlier in this tutorial) and add a rule to address the fact that the header links don't display as buttons the way they do in more standards-compliant browsers.
If you decide that the Internet Explorer 5 audience is too small for you to worry about, leave this small, cosmetic issue alone. If you want the navigation to look identical in this older browser, however, you can add the following code to the head of the document after the link to the style sheet:
<!--[if IE 5]>
<style type="text/css">
#header a,#header a:focus, #header a:hover; {
height: 1%;
vertical-align: bottom;
}
</style>
<![endif]-->
Conditional comments appear within HTML comments and include a conditional statement—or if statement—that looks for a particular version or range of versions of Internet Explorer. If the version is found, a custom rule is served to that browser. In this case, adding a dimension and vertical alignment to the navigation links fixes the spacing problem.
A full discussion about conditional comments is beyond the scope of this tutorial, but you can read more about them in the Conditional Comments posting on Peter-Paul Koch's QuirksMode blog. You can also read more about the list display problems in Internet Explorer in List Display Problems in Explorer for Windows – Part 1 on Community MX.
Now you know how to think in terms of CSS at every step of the web page development process—from starting layout comps in Fireworks to completing the pages in Dreamweaver. If you encounter any problems with your CSS or markup while following this tutorial series, compare your code with the completed examples included in the tutorial sample files. You can also study the CSS comments after each property and value in the blimey.css sample document. CSS comments begin and end with a slash and asterisk combination (/* and */). Commenting is a best practice that helps team members understand the thinking of other members on the team. They can also help solo designers recall their own thought processes. For example, six months later a comment may help a designer remember the purpose of a particular property.
Another troubleshooting method is to make sure that the page validates for markup, CSS, and accessibility. Checking these critical factors using the free Firefox Web Developer Toolbar quickly reveals problems and gives you clues about how to fix them.
You can also validate your markup and validate your style sheet at the World Wide Web Consortium (W3C) website.
For more information about CSS, visit the CSS topic page in the Dreamweaver Developer Center.
Tutorials and samples |
Dreamweaver user forum |
More |
| 02/09/2012 | How to Remove White Space? |
|---|---|
| 09/10/2010 | How to disable some HTML and CSS property's |
| 02/10/2012 |
Difficult to place tag... Please help!
|
| 02/10/2012 | Photo Gallery for mobile devices |
Dreamweaver Cookbook |
More |