Using Dreamweaver CS3 and CSS To Control Page Layout - Part 1

One of the things I love about Cascading Style Sheets (CSS) is the ability to control the layout of a web page without having to use presentational markup. A common misconception when designing a page layout with CSS is that it is a difficult task, especially if you are new to the language. I think this is mainly to do with the fact that there are so many browser inconsistencies around and the fact that there are so many different techniques on the web today. When I first started out using CSS to design layouts I often found myself scouring the web and finding quick and easy layout technique that would give me a fast result without understanding how it works. This is something that I don’t want you to do, I want you to understand how the techniques I use work. So if you haven’t done so already Subscribe to the RSS Feed so you don’t miss the rest of the series.

Create a CSS Layout Test Site

First thing is first let’s create a new site definition to house our Layout Test Site.

1. Launch Dreamweaver 8 and choose Dreamweaver Site from the Create New column in the Start Page menu. Alternatively, once you launch Dreamweaver, choose Site > Manage Sites > New, then click Site. Click the Advanced tab if necessary.

2. In the Site Name text box, type CSS Test Layout.

3. Click the file folder icon next to the Local Root Folder text box.

4. In the Choose local root folder dialog box, browse to an appropriate place on your hard drive and click the New Folder icon to create a new folder called css_test_layout.

5. Select the css_test_layout folder as the local root folder for your site.

6. Click OK to accept these minimal settings. If you came to the Site Definition dialog box from the Manage Sites dialog box, click Done from within the Manage Sites dialog box.

Now that you have your site defined, I will guide you through the first exercise, Centering a Design.

Use Dreamweaver and CSS to Center a Design

Now the issue of screen readability, given today’s modern monitors this is becoming increasingly important. One way many designers have tried to accomodate this issue is by centering their designs. So rather than span the full width of the screen these type of designs only span a portion of the screen hense easier to read line lengths. A lot of web designers / developers when starting out often ask How do you center a design in CSS? Well let me show you.

Dreamweaver and CSS Layout

1. Create a New HTML Page. From the Start Page > Create New Column select HTML. If you have not got the Start Page displayed you can also choose File > New; then from the Basic page category, select HTML. Click Create.

2. Save the File in the root of the CSS Test Layout site and call in center_layout.html.

Using Auto Margins

OK let’ say you have a typical layout that we want to center the WRAPPER div horizontally on the screen.

<body>
<div id="wrapper">
</div>
</body>

To achieve this all we have to do is define the width of the wrapper div and set the horizontal margins to auto.

#wrapper{ width: 720px; margin: 0 auto;}

You could easily set the width of the div as a percentage of the body or relative to the size of the text using ems. Now for those people who still use IE 5.x and IE 6 in quirks mode (god forbid), they don’t honor auto margins, so what IE does do is misunderstand text-align: center, therefore centering everything instead of just the text. So we can use that to center everything in the body tag then realigning the contents of the wrapper back to the left.

body{ text-align: center;}
#wrappper{ width: 720px; margin: 0 auto; text-align:left; }

A bit of a hack but no adverse effects. One more thing to make this work in all browsers is to set a min-width property to the body element. Because in Netscape 6 when the width of the browser window is reduced below the width of the wrapper then the left side of the wrapper spills off the side of the page.

body{ text-align: center; min-width: 760px;}

Use Positioning and Negative Margins to Center a Design

The auto margin method does work well, but if you don’t like the hack that you need to use to satisfy IE5.x and also the fact that you must style 2 elements instead of one then using this method maybe for you.

As we did before we define the width of the wrapper div then we need to set the position property to relative and then set the left property to 50%. This positions the left edge of the wrapper in the middle of the page.

#wrapper { width: 720px; position: relative; left: 50%; }

AH but I hear you say, I don’t want the left edge of the wrapper centered I want the middle of the wrapper centered. By applying a negative margin that is half the width of the wrapper then it will acheive what we are after.

#wrapper { width: 720px; position: relative; left: 50%; margin-left: -360px; }

It is very useful to have different techniques to center a design as you may need to use them both one day.

Don’t forget to Subscribe to the RSS FEED so you don’t miss Part 2, where I will show you how to use Float-Based Layouts to create a 2 column design.


| del.icio.us | Digg it | Furl | reddit | StumbleUpon | Yahoo MyWeb

You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

9 Responses to “Using Dreamweaver CS3 and CSS To Control Page Layout - Part 1”

  1. Hi, could you write a post about how to make a design (a wordpress theme in this case) fluid width as well as point out the benefits to using a fluid width design vs fixed width?

    Keep these posts coming, I’m enjoying them! :)

  2. Oops, in case it wasn’t clear, I’m talking about changing a fixed width design to fluid width, thanks!

  3. Excellent!, keep up the good work

  4. Hi,

    Question. If you go to http://www.embodicreativesolutions.com you will see that I am only trying to create a page holder at the moment.

    I am pretty new to all of this should go without saying I guess.

    What I would like to know is how do I get the jpeg that I created to auto adjust it’s size in relation to the size of the persons screen who is viewing it?

    Does that makes sense?

    Also I can’t seem to get the white borders to disappear. I created my file in dreamweaver cs3and uploaded it as an index file, along with the jpeg.

    I am lost. Any suggestions or html code that you could suggest to make this happen?

  5. @Dave

    With the image resizing, Using CSS you can giv the image a width as a percentage and that should do the trick.

    Shoot me an email from the contact page and let me know how it goes

    Cheers

    Daniel

  6. I am a little off topic maybe you can help me I am trying to get some source to get photos to auto resize and only fill the screen vs it needing to be clicked on to resize the photo to fill the screen.

    thank you.

  7. I’m trying to float the page and i’ve tried all that above and nothing happens!

    I don’t know much about css so i’m afraid i’m doing something very wrong.

    I put

    in my html page and
    than i created a css file with the code
    #wrapper{ width: 720px; margin: 0 auto;}
    I linked the css to my html and nothing the image just sits there.

    Help please,

    Thanks,
    Haideh

  8. Daniel, you start out great in this article, by explaining step by step how to set up the site. Then from the header Using Auto Margins, you’ve lost me. You are just writing the code, and not specifying what to do when, or in what document (is there a separate style sheet here, or not?). As a newbies instruction, it’s not very good.

    I know full well how to set up a new site in DW, but I’m not yet understanding the coding behind the wrapper, and that is the part I need step by step. It would be a good idea to say what you are to write where and when, and what the code is supposed to look like when you’re finished.

  9. I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.

Leave a Reply