Solved

center contents of webpage for all browsers and screen sizes

Posted on 2006-06-19
3
339 Views
Last Modified: 2013-12-16
I am trying to create a website that has the contents in the center of the page with a different background color for the area to the left of the left hand-margin as well as a different color for the area to the right of the right-hand margin. An example of what I am talking about can be found at www.icemiller.com.  It appears that I accomplished my goal when I am in Dreamweaver but when I view the page in internet explorer some of the controls and flash movies are in the margins and are not centered on the page. Can anyone explain how I can fix this problem? I am new to web development so any help would be greatly appreciated.

Thanks,

Ryan Wade
0
Comment
Question by:tankwade44
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 125 total points
ID: 16940440
Okay, what's happening is that the background of the body is set to grey, and then within the body either a div or table is used to stop the content stretching out to the width of the screen.  As DIV's are the recommended practice, my example below uses that approach.  The background color of the DIV is set to white, which makes it appear that there is a grey border.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Title Here</title>
    <style type="text/css">
        body {margin:0; padding:0; background-color:#dddddd;}
        .container {margin:0 auto; width:600px; background-color:#ffffff; text-align:center; border:1px solid #aaaaaa;}
    </style>
</head>
<body>
    <div class="container">
        <h1>My Page</h1>
        <p>Page content here.</p>
    </div>
</body>
</html>
0
 

Author Comment

by:tankwade44
ID: 16942974
Thanks a lot for your help.  I used the code above and it worked perfectly. I appreciate your help very much.

Ryan Wade
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16943013
You're welcome!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question