Dreamweaver II | CSS Web Site Design


CSS Web Site Design

With strong browser support, CSS is becoming the standard in Web development.

You've seen how CSS can format text, but just imagine the magic it could work with an entire page layout.

CSS sites are easier for you to maintain and more accessible for your site visitors. CSS has changed how the Web looks—and works.

Dreamweaver makes designing with CSS easy by providing a comprehensive selection of browser-tested page layouts that are Web Standards approved. All you have to do is dive in!

In this lesson, you can expect to:

Explore the different types of CSS layouts.
Learn how to use the box model to determine column widths.
Work with absolute positioning.
Learn how to align images in CSS designs.
Incorporate multiple page layouts.

 

 

 

 

Div is short for "division." Hence, divs are used to divide page content into logical sections.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The sidebar1 div is floated, so it needs a defined width. The mainContent div isn't floated, so it doesn't require a width value, it simply expands to fill whatever space is available.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Internet Explorer 5 interprets the box model differently. Your content areas may look more narrow in IE 5 than other browsers. However, it's likely that only a scant few visitors use this browser version.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Experiment with overlapping background patterns and colors. A gradient background applied to the mainContent div could overlap the solid background color applied to the container div.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Use extra line-height in liquid layouts. The extra space between the lines will guide the reader's eye across the screen.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The overflow property determines what will happen if the content doesn't fit the div. The options are visible, hidden, or scroll.
 

CSS Layouts Refresher

 

 

You might have used CSS layouts in your previous Dreamweaver studies, but let's refresh your memory.

CSS positioning (also known as CSS-P or tableless layout) separates the content (organized in HTML) from its presentation (formatted in CSS).

Within the HTML document, content areas such as page headers, nav bars, sidebars, and footers are wrapped in <div> tags.

In the CSS file, these divs can then be styled in a myriad of ways: assigning page positioning, widths, borders, margins, and more.

Let's set up a CSS layout now. Create a new folder on your desktop called "csslayouts". Define a new site (Site > New Site), selecting the "csslayouts" folder as the local root folder.

Go to File > New and choose Blank Page and the HTML page type. Select the 1 column fixed, centered, header and footer layout. Create a a new layout CSS file, saving to your "csslayouts" folder.

Check out Code view and notice the various divs in the HTML source code, such as <div id="header"> and <div id="mainContent">. Head back to Design view when you're done.

Fixed Layouts
One-Column Fixed Layout

The one column fixed layout is pretty basic. You have a header, a content area, and a footer—all in normal flow. One div follows another. The widths are fixed to the assigned sizes. No surprises here.

Take a look at the CSS Styles panel to see how this layout is put together.

Remember, double-click to edit a rule in the CSS Rule Definition dialog, or use the Properties pane for quick access.

The body tag selector sets the page background to #666666 (a mid-tone gray). In most cases, you'll want to choose a more exciting background color, or even add a background pattern. The font family and text color are also defined here. The default 100% font size is rather large—you might consider sizing it down to 80%. The text-align "center" property is a hack used to center the layout in Internet Explorer 5.

Next, take a look at the #container ID selector. The container div holds the header, mainContent, and footer divs. It is set to 780 pixels wide, defining the width of the layout. You could make the container a little wider or a little narrower, depending on your page design. You could also change the background color and border style of the container div.

0 auto is shorthand for 0 auto 0 auto, which is shorthand for top-margin:0; right-margin:auto; bottom-margin:0; left-margin:auto.

The container div's top and bottom margins are set to zero, and the left and right margins are set to auto. This centers the layout in the browser. Text-align is set to "left" here, overriding the "center" text-align setting on the body tag.

Take some time to explore this layout, refreshing your memory on how the divs and properties work. Then let's move on to a two-column layout.

Multi-Column Fixed Layouts

Go to File > New and choose a 2 column fixed, left sidebar, header and footer layout. Save the CSS file into your "csslayouts" folder.

Just as you might expect, this layout is divided into two columns, with a header and footer. A very useful layout that you see all over the Web (dressed up with color and graphics).

Look at the CSS Styles panel to see how the columns are put together. The sidebar1 div is given a width of 200 pixels and set to float "left."

The float "left" property pushes the sidebar1 div over to the left, allowing the mainContent div to move up to the right.

The mainContent div has a left margin of 250 pixels. This keeps the mainContent div in a clean column, so it doesn't wrap around below the sidebar.

If you look at the Code view, you'll see a <br> tag with a class of "clearfloat" just above the footer. The "clear" property forces the footer to stay below the floated columns (rather than wrapping around the side). We'll talk more about clearing floats later in the lesson.

Column Adjustment and the Box Model

You might need to adjust the column widths of a fixed layout to fit your design. This is easy to do, but first, it is important to understand the CSS box model. Each element on the page sits inside a box. If the content is 100 pixels wide, the box will be 100 pixels wide.

If you add a 10 pixel border, the overall width adds up to 120 pixels.

You might also add some padding (space between the content and the border):

And a margin (space outside of the border):

The overall width of the box is a sum of the content, padding, border, and margin.

All of these values have been calculated into your current two-column layout. The sidebar1 div has 10 pixels of right padding, 20 pixels of left padding, and a width of 200 pixels. This adds up to 230 pixels altogether.

The padding values are always listed in the order Top, Right, Bottom, Left—remember TRouBLe as a mnemonic.

Remember how the mainContent div has a 250 pixel left margin? This safely clears the 230 pixel area of the sidebar and leaves a 20 pixel gutter.

The width of the mainContent div isn't explicitly defined, but you can figure it out by with a little math:

This means that you have 490 pixels of space to work with. If you insert an image that is 490 pixels wide, it will fit just fine:

However, if you insert an image that is 500 pixels wide, it will drop down below the left column:

This phenomenon is fondly known as float drop. To fix it, use the box model to calculate your layout. If you want the mainContent div to be 600 pixels wide, you could make the sidebar1 div more narrow to compensate, or make the container div wider, or remove the padding.

Column Colors

One more issue to cover before we move on to the next layout—column colors. You may have noticed that the background color of the left column doesn't stretch all the way down to the bottom of the page. This is different than a two column table layout, where the columns always even out. In CSS layouts, each column is a separate div with a different height.

The new trend in Web design is to just go with the flow—allowing each column to be different.

Who says columns have to line up? Magnetic lenses uses a clean white background and allows the columns to stagger.

However, if your design dictates a more structured appearance, you can easily create this kind of effect:

If you scroll to the bottom of the Pen Cei Guesthouse homepage, you'll find that both columns stretch all the way to the bottom.

The solution is to apply a background image to the container div. This is called the "faux column" method. The container div wraps around both columns, so the background image will stretch to the full height of the layout.

Start by creating a GIF image the width and color of the left column.

The background image should be sized to fit the width of the sidebar. The height doesn't matter—the image will tile down vertically.

Edit the #container ID selector using the CSS Styles panel. In the Background category, browse to select the background image and set it to repeat-y, so it tiles vertically. Then select a contrasting background color to fill in the space on the right.

The cream-colored background image is set to tile vertically down the left side of the container div. The gray background color fills in the right side.

Background images are a great way to add depth and texture to your page design. For a rough, distressed look, you might create a background image with a "torn edge." Or you could experiment with patterns or gradients. Color is free on the Web, so take full advantage!

Now on to our next layout...

Moving and Aligning Columns

Go to File > New and create a 2 column fixed, right sidebar, header and footer layout. Save into your "csslayouts" folder.

The right sidebar layout looks familiar. Same idea as the left sidebar layout, but this time, the sidebar div is set to float "right." The mainContent div has a right margin rather than a left margin.

To create a equal-length column effect, you could use the same background image as before, but this time, set the position of the background image to align "right" and "top."

You can change the horizontal position of the background image to have it tile down the right side of the div.

You can resize the column widths as you please, paying due respect to the box model, of course. It is also possible to change the container's alignment to left rather than center. Just remove the "auto" margins from the #container ID selector. Also, delete the "text-align: center" property from the body tag.

The designers of Holy Shitake decided to left-align this layout. Dreamweaver layouts are centered by default, but you can easily change this setting.

Three Column Grids

One more fixed layout to check out. Go to File > New and choose the 3 column fixed, header and footer layout.

The three column grid is another popular layout seen all over the Web.

The justteeshirts home page packs a lot of links into this three column layout.

How is this put together? The sidebar1 div is given a width of 150 pixels and set to float "left," and the sidebar2 div is given a width of 160 pixels set to float "right." The mainContent div squeezes in to fill the space between the two sidebars.

To create a faux column effect, create a background image with all three columns, then apply it to the container div.

This thin background image could tile vertically to create a three-column effect.

Liquid Layouts

Liquid layouts scale in relation to the browser window. The content will wrap to fit a small screen size:

View MoodMill in a browser and resize your browser to see how it adjusts.

Or expand to take full advantage of a large monitor:

The home page design looks good at both the small and large resolutions.

When using liquid layouts, consider the line lengths at large screen resolutions. You don't want a paragraph of text to stretch across the full width of the screen. Long lines of text are tiring to read—the eye has to read all the way across, then backtrack to find the beginning of the next line.

Dreamweaver offers several liquid layouts in its CSS repertoire. In most cases, I recommend the two or three column versions (it is better to have two narrow columns of text rather than one really wide column).

Go to File > New and select the 2 column liquid, right sidebar, header and footer layout. Save the CSS file in your "csslayouts" folder.

The float mechanics are the same as the fixed layouts, except the widths are set in percentages.

The container width is set to 80%. This helps to control the line lengths and allows a comfortable margin. However, you can easily edit the #container ID selector and change the width to 100% for a perfect fit.

Elastic Layouts

As we discussed earlier, line length is an important factor in legibility. This column of text looks great at the defined font size.

The small text fits the narrow column nicely.

However, if the user increases the browser font size, the text wraps in strange ways.

A larger font size looks squeezed in.

Narrow columns don't read well when only two or three words fit in each line.

An elastic layout presents a progressive solution. The width of the column scales in relation to the font size.

The wider column is a sized proportionally to the larger font.

How does this work? The column widths are defined using ems rather than pixels.

Sizing with Ems

You might have used ems to size type. An em is equal to the width of the letter "m." If you set the font size to 1 em, the text will display at the user's default font size. 0.9 em would be a little smaller than the default, 1.25 em larger. This is a scalable system that allows the user to resize the text to a comfortable size.

Entire layouts can also be sized using ems, so the columns scale in relation to the font size.

Go to File > New and create a 3 column elastic, header and footer layout.

This elastic layout is set up just like any other three column floated layout. However, the widths are defined in ems:



Preview in a browser to see how it works. Increase your font size, and notice how the entire layout expands.

When working with elastic layouts, one issue that might come up is image size. When the user increases the font size, the text gets bigger and the columns get bigger, but the images stay the same size. This could create gaps in the layout.

One solution is to use background images that tile to fill each div. For example, the header in this elastic CSS Zen Garden design is composed of a yellow background graphic with a diagonal stripe .

The yellow diagonal stripe pattern fills the Elastic Lawn header, even if the layout expands. The curved-edge graphics are set to align in each corner.

A different approach is to make the image bigger than necessary, then insert it in a div with an overflow value of "hidden."

In the Ungarbage home page, the default height of the header div is 211px.

If the div expands, more of the image will be revealed:

When the text size is increased, the height of the div grows, exposing more of the trash can image.

Hybrid Layouts

If you can't decide between a liquid or elastic layout, try a hybrid. Go to File > New and create a 3 column hybrid, header and footer layout.

The container div in this layout is set to 100%, so it expands to fill the entire browser window. The width of each sidebar is defined in ems.

Preview this layout in a browser to see how it works. Increase your font size, and make your browser smaller and larger. Do you like how the content areas adjust to fill the window?


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Check Code view as you work to get a sense of how your div tags are nested.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The z-index determines a div's position in the stacking order. A high z-index value will place the div on top. A low z-index value will place a div on the bottom.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If there is no containing block, the browser window is used to position the AP element.

 

 

 

 

 

 

 

 

 

 

 

 

Fixed positioning is not supported by Internet Explorer 6 and below.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tables still come in handy in "tableless" designs when presenting data or other grid-based information.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If you plan to use the same layout for your entire Web site, you can delete the body class selectors from the external style sheet. This will make your CSS panel easier to read.

 

 

Absolute Positioning

All of the layouts we've covered so far have used floats for positioning, shifting divs to the left or right. The content oozes into place.

Absolute positioning (AP) takes a completely different approach. Each div is positioned as an individual element, aligned to precise coordinates. Absolutely positioned divs are taken out of the normal flow of the document, which means that they are no longer affected by other divs.

The advantage is that you will be able to place the AP div wherever you want. The disadvantage is that you have to carefully plan the height of each content area to prevent unintended overlaps.

Setting Up Your Divs

Let's see how this works. Create a new document and name it "ap.html". Go to Insert > Layout Objects > Div Tag. Give the div an ID of "container".

Click inside the container div and press your Return key a few times to give yourself some space to work. Delete the filler text.

With your cursor planted inside the container div, go to Insert > Layout Objects > Div Tag. Give the new div an ID of "header" and click OK.

Delete the filler text, and type "Header" inside the div. Select the "Header" text and format it with h1 tags by choosing Heading 1 from the Format menu of the Property inspector.

Click your cursor below the header div, but still inside the container div. Insert another div (Insert > Layout Objects > Div Tag) and give it an ID of "nav". Type some fake links into the nav div, like "home, about us, news."

Click your cursor below the nav div. Go to Insert > Layout Objects > Div Tag and give the div an ID of "mainContent". Insert some dummy text inside this div (just copy/paste any paragraph).

Your document should look something like this—three divs nested inside the container div. They are in normal flow, with no positioning applied.

Positioning the Divs

Create a new CSS rule. Choose the ID selector type (or Advanced in Dreamweaver CS3) and type #header as the selector name. This ID selector will style the header div. Define the rule in a new style sheet file.

In the Background category, choose a background color for the header.

In the Positioning category, set the positioning type to "absolute". Give the div a width of "500px" and a height of "80px". Set the placement to "Top: 0" and "Left: 0". Click OK.

The result might look a little strange. The header div has been taken out of the normal flow. It is overlapping the other divs.

Let's line up the other divs. Create a new CSS rule, #mainContent.

In the Background category, choose a background color for the mainContent div.

In the Positioning category, set the position to "absolute" and the width to "500px". Don't enter a height value—it is uncertain how much content will go in this div, so we will just allow it expand down as necessary. Set the placement to "Top: 80px" (so it sits just below the 80 pixel header) and "Left: 0". Click OK.

Looking better, but what happened to the nav div? It is completely hidden behind the other divs. Let's move it up to the top.

Create a new CSS rule, #nav.

In the Background category, choose a color for the nav div.

In the Positioning category, set the position to "absolute" and the width to "200px". To make sure that the nav div is placed on the top of the stacking order, give it a high z-index value, like 10. Set the placement to "Top: 70px" and "Left: 150px". Click OK.

All three divs are in place. However, the left-aligned layout might not be the effect you want. On large browsers, there is a lot of empty space on the right—it doesn't feel balanced.

Centering the Layout With a Containing Block

How can we center this layout? You might have noticed that there is no "align-center" property in the Positioning category. Let's consult the World Wide Web Consortium, www.w3.org—always a good idea when you're not sure of the best approach to a challenge. The mandate is:

 
 

The box's position is specified with the 'left', 'right', 'top', and 'bottom' properties. These properties specify offsets with respect to the box's containing block.

 
 

Interpretation, please? A containing block is a div that contains other divs. In the page we are working on now, the header, nav, and content divs are nested inside the container div. This means that the container div can be used as a containing block.

However, another factor is involved—the containing block must have a position of absolute, relative, or fixed. There are four positioning types:

 
 

Absolute: An absolutely positioned element is pulled out of the normal document flow. It can be placed anywhere on the page.

Relative: A relative element stays in the normal flow, but it can be offset from its original position with the properties top, right, bottom, and left.

Fixed: A fixed element will stay in the exact same place, even when the browser window scrolls.

Static: A static element appears in the normal document flow. This is the default positioning type.

 
 

Our container div has a default position type of "static". To make it work as a containing block for its nested AP divs, change the position type to "relative".

Create a new CSS rule for #container.

In the Box category, set the width to "500px". To center the container div in the browser, set the right and left margins to "auto."

In the Positioning category, set the position to "relative." Click OK.

Save and preview in a browser. The container div is centered, and the nested AP divs are placed in relation to the container.

Overlapping Effects with AP

Jumping off from this basic concept, you can literally place elements anywhere on the screen, creating all kinds of overlapping effects.

The AP divs in Frank Was Here are outlined in orange above.

Dreamweaver provides two CSS layouts with AP elements. The 3 column, absolutely positioned, header and footer layout looks exactly like a 3 column fixed layout. However, the sidebars are absolutely positioned rather than floated. The container div is relatively positioned.

Each absolutely positioned sidebar opens up all kinds of options. The sidebar's status of "absolute" makes it qualify as a potential containing block. That means you can nest another AP div, setting its position in relation to the sidebar.

Below, I've inserted a div in the sidebar and given it a red background color. In the Positioning category, the position type is set to "absolute." The placement is set to "Top: 90px" and "Left: -20px". This moves the div down 90 pixels and over 20 pixels, in relation to the top left corner of the sidebar.

The absolutely positioned sidebar can be used as a containing block for more AP elements.

This is just a simple example, but think of all the cool overlapping effects you could create using this method.

Something to watch out for: Make sure that the content area is taller than the sidebars. The mainContent div is actually pushing down the footer. If the mainContent div is too short, the footer will be hidden behind the absolutely positioned sidebar columns.

The sidebar columns are overlapping the footer div.

You may have noticed an option in the Insert menu, Insert > Layout Objects > AP Div. This is a shortcut—it inserts a div that already has the position type of "absolute." You can drag the AP Div anywhere you want, or resize it using the handle bars.

Pretty cool, but the bad news is that the ID selector is saved as an internal style in the HTML file—not in the external style sheet. This means that the style won't be available on other pages in the site.

I recommend using Insert > Layout Objects > Div instead. It only takes a second to set the positioning using the CSS Styles panel, and you'll have the option to save the ID selector to your external style sheet.

Adding Content and Design Elements

With the CSS layout of your choice in place, text and images can be added quickly and easily, just as if you were working with table cells.

Needless to say, you'll start by deleting Dreamweaver's placeholder text. Then just paste, type, or insert any content that you like.

Adding a Top Nav

You might decide to add a top nav below the header. There are several ways to go about it.

The most direct method is to add two nested divs inside the header div. Insert the banner image in the banner div, and the nav list in the topnav div.

To insert a nested div, click inside the header div, then go to Insert > Layout Objects > Div Tag. Choose "at insertion point" from the Insert menu.

Then click below the banner div and insert another div for the topnav. Sometimes it can be tricky to insert your cursor in the right place, so if you have any trouble, just switch to the code view and type in the div tags yourself.

Another approach would be to insert the banner.gif as a background image.

Set the position of the header div to "relative" and the position of the nested topnav div to "absolute." Then align the topnav div along the bottom-left corner of the header div. You'll find these properties in the Positioning category of the Rule Definition dialog.

Image Floats

If you need to align an image to the right of a text block, set the image to float: right. Create a class style with the float property (found in the Box category of the Rule Definition dialog), then apply it to the image.

If you would rather align the image along the left edge, set it to float: left.

To float several images in a column, add the property clear: right. This will force each floated image to clear down to the next row. You could also add a top margin, allowing some space between the images.

To create a photo gallery with rows and columns of images, set each image to float: left.

You can use this same method to float an image together with a caption. First, insert the image and caption in a div. Then, create a class style with the float property and a width property (both found in the Box category of the Rule Definition dialog).

Don't forget to apply a width to the floated div. Floated elements must have a defined width to work properly. Images already have a width, but you have to specify a width for divs.

Clearing Floats

Floats are a very useful layout technique, but there is one glitch to watch out for. Let's say you start out with a long, narrow image and a short paragraph of text.

You float the image to the right, but then something strange happens.

The float is working properly—the image has floated over to the right, and the paragraph has shifted up to fill its place. However, the image is now overlapping the footer at the bottom of the page. Not the effect you were after.

When you float an image, it is taken out of the document flow. It can't push down the footer; it has no physical presence.

Normally, a longer text paragraph would do the job of pushing down the footer, wrapping below the image. However, if your image is taller than your text area, you will have to resort to some extra markup to force the footer to stay below the floated element. This is called "clearing the float."

Dreamweaver uses a clearfloat element in the 2 column fixed, left sidebar, header and footer layout.

The mainContent div is followed by a <br> tag with a class of "clearfloat". This is the clearing element.

Here, the clearing element is inserted after the closing tag of the mainContent div. This forces the container div to expand to contain the floated sidebar.

A comment tag informs you that the clearing element should follow the mainContent div in order to force the container to contain the child floats (in this case, the floated left sidebar). If it weren't for this clearing element, a long sidebar would overlap the footer.

Open the twoColFixLtHdr.css to take a look at the "clearfloat" class selector that is applied to the br tag.

The clearfloat class selector is saved in the external style sheet.

The clearfloat class selector is set to "clear: both", meaning it will clear any elements, whether floated left or right.

The height, font-size, and line-height are set to the smallest possible amount, to ensure that the clearfloat element does not cause any extra vertical space that might create a gap in the layout.

You can use this technique to clear a float inside any div, anywhere in your document. Let's go back to the example with the long, narrow image and the short paragraph of text. To fix the layout, just add an extra clearfloat element inside the mainContent div.

The HTML code would look like this:

Here, the clearing element is inserted before the closing tag of the mainContent div, forcing the mainContent div to expand to contain the floated image.

Just one extra line of code. Not bad for a hack.

Centering an Image

If you need to center an element within a div, set the left and right margins to "auto."

Extending the Design

When you finish your first page design, it can be used to produce many, many more pages for the Web site. If all pages will share the same layout, use a copy of the first page to make the second page, and insert the new content. The .css file will already be linked and active. Repeat the process to create all the remaining pages.

If your Web site will contain multiple page layouts, you can use the body class selector to customize each page.

Each Dreamweaver CSS Layout has a unique class applied to the body tag:

This class identifies the 1 column fixed, centered, header and footer layout. This class identifies the 2 column fixed, left sidebar, header and footer layout.

Each div is formatted with a descendant selector:

.oneColFixCtrHdr #mainContent
This descendant selector applies to the mainContent div in the 1 column fixed, centered, header and footer layout.

.twoColFixLtHdr #mainContent
This descendant selector applies to the mainContent div in the 2 column fixed, left sidebar, header and footer layout.

This might look like gibberish, but it serves a very useful purpose—the mainContent div in the 1 column layout can be formatted differently than the mainContent div in the 2 column layout.

The first step is to identify the divs that will vary between the two layouts. I've highlighted them below in green:

The mainContent div is a different width in each layout. Also, the sidebar1 div only exists in the 2 column layout.

The header, footer, and container divs don't vary—they use the same formatting in each layout. This means we can remove the body class selectors from these divs. After we meld the two style sheets, our selectors will look like this:

Combining the two style sheets takes a little copy/paste work.

First, create the one column layout. Save the oneColFixCtrHdr.css file in your local root folder, along with the HTML file.

Next, create the two column layout. Save the twoColFixLtHdr.css file and the html file in your local root folder.

Open the oneColFixCtrHdr.css file. Select the .oneColFixCtrHdr #mainContent descendant selector and go to Edit > Copy.

Open the twoColFixLtHdr.css file. Go to Edit > Paste to add the oneColFixCtrHdr #mainContent descendant selector.

Now, remove the body class selectors from the divs that won't vary between the two layouts. Delete the .twoColFixLtHdr body class selector from every div except "sidebar1" and "mainContent."

To finish up, go to File > Save and save the style sheet as global.css in your local root folder.

Open the one column html file. Using the CSS Styles panel, select the oneColFixCtrHdr.css file and click the trash can icon to delete it. Then click the link icon and browse to attach the global.css style sheet.

Repeat for the two column html file. First, delete the twoColFixLtHdr.css external style sheet. Then, attach the global.css style sheet.

Both layouts are now attached to the global.css external style sheet. If you make any changes to the common selectors like "body" or "container", it will affect both layouts. If you make a change to a descendant selector, like .oneColFixCtrHdr #mainContent, it will only affect the mainContent div in the one column layout.

The Capgemini Web site shown below is an excellent example of a multi-layout design. Here we see that some content areas from the home page are also used on second-level pages, like the header and navigation. The second-level pages have some new content areas of their own, like the right column.

The use of CSS throughout the Capgemini Web site provides an innovative, classy, and consistent look—exactly what this company wants to convey to its audience.

   

 

Review how to create basic rollover images.
Explore different types of event handlers.
Learn how to create advanced image rollovers and swaps.
Learn how to initiate pop-up windows and alert messages.
Learn how to create menus and panels with Spry widgets.
Learn how to add custom behaviors from the Adobe Exchange forum.
 

Exercise
Design a video game review portal using CSS layouts.

Discussion
Share your thoughts on Web design with your fellow students.