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.
    Windows XP SP2 - theme: Thallos
    AMD Athlon 64 X2 4600+ | ASUS M2N32-SLI Deluxe | 2 * 1024 PC2-6400 Mushkin DDR2-800 | eVGA GeForce 6800XT 256MB | Creative Sound Blaster X-FI Music
    5 * 320GB Seagate Barracuda SATA-II 3Gb/s in RAID 5 | Lite-On 16x DVD-RW | Mitsumi 7-in-1 Floppy drive and card reader
    Samsung SyncMaster 204B 20" TFT LCD | Logitech G15 Keyboard | Logitech G7 Mouse | Seasonic PC160SK Headset

  4. #4
    Join Date
    Jan 2004
    Location
    United Kingdom
    Posts
    610
    opera dooesn't understand margin: 0 auto;
    More of a journal than a blog.

    Truly great madness cannot be achieved without significant intelligence.
    GMail | Mezzoblue | 1976 Design | Zeldman | Justwatchthesky | Jon Hicks | Airbag | All In The Head

  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 12: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