Solved

center contents of webpage for all browsers and screen sizes

Posted on 2006-06-19
3
314 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now