www.webdeveloper.com
Results 1 to 6 of 6

Thread: Centering the page with css question

  1. #1
    Join Date
    Sep 2004
    Posts
    11

    Centering the page with css question

    Once again i have a simple question i am sure.

    I am trying to center a page using CSS and not having much luck in IE. The following code works with Netscape and Mozzila. Any suggestions would be greatly appreciated!!

    <html>
    <head>
    <STYLE TYPE='text/css'>
    body { width: 800px; margin: 0 auto; }
    </STYLE>
    </head>

    <body>
    This is a test of page centering
    </body>
    </html>

  2. #2
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    First try using a full valid doctype to put IE into standards mode. If that doesn't work then you have to use text-align:center to get IE to center things; it doesn't understand margin:auto.

  3. #3
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1,592
    Originally posted by ray326
    it doesn't understand margin:auto.
    IE6 does, just not older versions of IE.

  4. #4
    Join Date
    Jan 2004
    Location
    United Kingdom
    Posts
    610
    opera dooesn't understand margin: 0 auto;

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>center contents</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    <!--
    body {text-align: center}
    #alignment {text-align: left; margin: auto auto; width:60%;}
    p {background:red;}
    -->
    </style>
    </head>
    <body>
    <div id="alignment">
    <p>contents</p>
    </div>
    </body>
    </html>

  6. #6
    Join Date
    Sep 2004
    Posts
    11
    Thanks all, your help has been invaluable!!!
    Last edited by MithrilRain; 09-10-2004 at 01:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles