Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) What is the best way to center the entire page with div and css?

  • What is the best way to center the entire page with div and css?

    Posted by Hau Li on January 13, 2009 at 9:32 pm

    Hi,

    I was having headaches with tables, so I drop a jpeg that I made and sliced in photoshop into dreamweaver and traced it which creates div tags. I uploaded it and everything shift to the left again.
    I wasn’t able to make tables since it seems to give me that 1 pixel gap between the picture and the table…

    What do you think of my WIP site?
    http://www.tvholicjamie.com

    Fernando Mol replied 17 years, 3 months ago 3 Members · 2 Replies
  • 2 Replies
  • Abraham Chaffin

    January 13, 2009 at 10:01 pm

    You can surround your content with a div that is set with the specific width of your page content and then assign a margin of left auto and right auto:

    #main_wrapper {
    width: 900px;
    margin: 0 auto 0 auto; /* Sets the margin properties for an element using shorthand notation (top, right, bottom, left) auto right and left will centre it in the browser */
    }

    Abraham

  • Fernando Mol

    January 22, 2009 at 6:23 am

    As Abraham says, you should add a new div to the code covering the entire body of your page.

    <body>
    <div id="main_wrapper">

    <!-- your content here -->

    </div>
    </body>

    But you’ll also need to add a relative position attribute to the main_wrapper div because all of your “Layer” divs are absolute positioned.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy