In this section, you will begin the transformation of the layout from tables to CSS. You will learn how to make good use of a wrapper div and investigate the merits of utilizing a zeroing selector within your style sheet.
Your first task will be to set the wrapper div. The wrapper acts as a container to all the other elements within your design. The current layout enables you to add any excess space in the browser's viewport to the right of the design; that is, the area to the right of the banner will flex to fill up the full width of the browser window. This can make a page look a little lopsided if it is left-aligned. Your first task is to center the design and make it a fixed-width design in keeping with the current layout's content area.
When you create a new page, keep the page you generated earlier as a reference point for when you make your design changes. Save this new page into the root of your local site and name it health.html.
Next, create a new CSS file (if necessary, refer to my series Designing with CSS for details). Save this new CSS file to the CSSFiles folder you created earlier as health.css. You will link this to your health.html page shortly.
Eliminate the browser default values in your health.css file by implementing a zeroing selector at the top of the style sheet, as shown in the following example:
html, body, ul, ol, li, p, h1, h2, h3, h4, h5, h6, form, fieldset {
margin: 0;
padding: 0;
border: 0;
}
Using a zeroing selector removes the browser default values, which can vary greatly from browser to browser.
Next, fix what I consider to be an annoying problem with Firefox: if a page is shorter than the viewport, it jumps around as Firefox removes the scroll bar and then adds it again for longer pages. This selector causes problems in the Macintosh version of Internet Explorer. To be on the safe side, hide this rule from that browser by using a comment filter, as shown in this example:
/* hide from IE mac \*/
html {
min-height: 100%;
margin-bottom: 1px;
}
/* end hiding from IE5 mac */
By setting the HTML height to 100% and then adding a one-pixel margin to the bottom, you can force Firefox to draw a scroll bar. This prevents the annoying page jump that you might see on shorter pages in that browser.
Finally, set up your default values on the body element:
body {
font-family: Arial, Helvetica, sans-serif;
color: #000;
}
I discuss the odd default font in the previous series. It prevents some scaling bugs at smaller sizes in Internet Explorer. You will scale off this value in other selectors, as you will see shortly.
Now that your first three selectors are in place, you can link your health.css file to your health.html page. After the CSS file is linked, view your selectors in the CSS panel. Either edit your CSS code by hand or let Dreamweaver do some of the footwork for you. One change in the way you link CSS files in Dreamweaver 8 is that you now control the media type from the Attach Style Sheet dialog box. For this example, set the media type value to Screen.
Follow these steps:
A good width for a wrapper is 770 pixels because viewers with a maximized browser using a screen resolution of 800 x 600 do not need to scroll horizontally to view your content. Horizontal scrolling is something you really want to avoid. There is little else that is more annoying!
Your header div doesn't need a width; you can allow it to expand to the full width of the wrapper. A div will always expand to the width of its containing element. This is a good thing because it prevents the need for specifying width values unless you want to constrain the width.
Follow these steps:
You now need to add the divs to your HTML file. Switch to code view and enter the following code:
<body> <div id="wrapper"> <div id="header"> <!-- close header --> </div> <!-- close wrapper --> </div> </body>
You will notice that I have commented the closing <div> tags. This is a good practice to get into because it is very easy to lose track of them—and time-consuming to track them down within a large page.
With your code in the health.html file, you can now switch to Design view and complete the following steps:
Figure 2 shows you what your work should look like at this point.
Figure 2. Banner and wrapper divs in position on the page
You have made a good start on converting your site from tables to CSS. With the header and wrapper now in position, you can learn how to implement an inner-wrapper div and fake the appearance of 100% tall columns by using a background image. Part 2 shows you how to do this.
Applying CSS from Screen to Print to Handheld – Part 2: Layout and Background Images