www.webdeveloper.com
Results 1 to 6 of 6

Thread: centering page

  1. #1
    Join Date
    Jul 2010
    Posts
    14

    centering page

    Hi,
    I have a special problem:
    My main page is a div and I would like it to always stay centered. I also do not want to use the "onload()" event to handle this. If i use <center> then everything inside the div is positioned relative to the screen and not the div (absolute).
    Any suggestions?

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    can you post the code or give us a link?
    "Hippies.They're everywhere. They wanna save the earth, but all they do is smoke pot and smell bad."-Cartman

  3. #3
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    All you need to do is wrap your content div in a div and then center the wrapper div.

    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <style type="text/css">
    <!--
    
    #wrapper {
    width: 600px;
    margin: 0px auto 0px auto;
    padding: 0px 0px 0px 0px;
    height: 200px;
    border: 1px solid red}
    
    -->
    </style>
    
    </head>
    <body>
     
    <div id="wrapper">
        <div id="content">
            <h1>Page contents go in this div</h1>
        </div>
    </div>
     
    </body>
    </html>

  5. #5
    Join Date
    Jul 2010
    Posts
    14
    thanks everyone! I also found another way though. give the div left:50&#37;; and then
    margin-left:minus half the width.

  6. #6
    Join Date
    Mar 2010
    Posts
    2,803
    no problem

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