1 Reply Latest reply: Jul 17, 2009 5:03 PM by Cheryl D Wise RSS

    Keeping my page centered in the browser

    BearHNC Community Member

      Hello,

      I would like to keep my page centered in a brwser no matter how big the browser window is, I thought that is what the absolute middle alignment tag did, but think I may be wrong. Here a site that gives an example of what I am trying to do, can anyone help?

       

      http://www.nissanusa.com/gt-r/index.html

       

       

      I don't know if this changes the playing field but the page has an embedded flash site.

       

      Thanks in advance

        • 1. Re: Keeping my page centered in the browser
          Cheryl D Wise MeganK

          Centering a page in a web browser requires the following:

           

          1. A valid doctype - Dreamewaver by default adds this to your pages.
          2. A container with a specified width - it can be in pixels, ems or percents
          3. The container  must have margin-right: auto; margin-left: auto;

           

          Example:

           

          #container {

              width: 775px; /* to fit in an 800px wide browser */

              margin: 0 auto; /* no top or bottom margin and auto left-right */

          }

           

          <body>

          <div id="container">

          <!-- site code here -->

          </div>

          </body>