Centering a Div Horizontally working for all browsers including IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boien
    New Member
    • Dec 2006
    • 3

    Centering a Div Horizontally working for all browsers including IE

    I have a div container that i have created now i just want to make sure that its horizontally centered in any browser and in any resolution, so that when ever its on 800x600 or 1280x1024 its STILL centered horizontally no matter what, instead of sticking to the left side of the browser window in different res' or window adjusting of any kind.
    Thank you kindly
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    In your main container div add margin:0 auto;

    Comment

    • pravinda
      New Member
      • Dec 2006
      • 23

      #3
      <body>
      <div align="center"> </div>
      </body>

      Comment

      • AricC
        Recognized Expert Top Contributor
        • Oct 2006
        • 1885

        #4
        Originally posted by pravinda
        <body>
        <div align="center"> </div>
        </body>
        The align attribute is deprecated here is an example how you can align an element.
        [html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
        <title>Test</title>
        <style type="text/css">
        body
        {
        background-color: blue;
        }
        .clsWrapper
        {
        text-align: center;
        }
        .clsTest
        {
        height: 250px;
        width: 250px;
        background-color: white;
        border: 1px solid black;
        }

        </style>
        </head>

        <body>
        <div class="clsWrapp er">
        <div class="clsTest" >
        Hello World
        </div>

        </div>
        </body>
        </html>[/html]

        Comment

        Working...