how to center a webpage in CSS

css

Solution

Whichever element you want centered - set an explicit width and then set left/right margins to `auto`

#main { width:995px; margin:0 auto; }

...this will center the element in its parent. If you were to center `#main`, it would be centered on the page (assuming your `body` has 100% width)

EDIT

Try making your background image apply to `#main` instead of `body`. Or, center the background image using `background-position`, or shorthand:

body { background:url(../back.gif) repeat-y center top; } 

Cheers

Problem

i am i am new in CSS.. i have converted my psd file into html/css.. now i want to move my webpage page into center of the window.. i tried some code and that code align only text the background image "back.gif" remains at left.. here is my html and CSS code" ``` **HTML** <body> <div id="main"> <div id="header"> <div id="logo"> <img src="logo.gif" /> </div> </div> <div id="menu"> <img src="images/menu_07.gif" /> <div id="m"> <ul> <li> <a href="index.php">Home</a></li> <li> <a href="pages.php">Pages</a></li> <li> <a href="donor.php">Donor</a></li> <li><a href="seeker.php">Seeker</a></li> <li><a href="hospitals.php">Hospitals</a></li> <li><a href="lifesaving.php">Life Saving Contacts</a></li> <li><a href="contactus.php">Feedback</a></li> </ul> </div> </div> <div id="content"> <div id="center" align="center"> <h3>WELCOME TO ADMIN AREA</h3> <p id="ajk">AJKBLOODBANK.COM</p> <?php echo "welcome!".$_SESSION['username']; echo "<br>"; echo "<a href=logout.php>Logout</a>&nbsp;"; ?> </div> </div> <div id="footer"> </div> </div> </body> **CSS** body { background:url(../back.gif) repeat-y; padding-left:105px; height:900px; text-align: center; margin:auto; min-width: 760px; } div#main { width: 720px; margin: 0 auto; text-align: left; } #header { width:787px; margin-top:10px; } #menu { width:787px; float:left; margin-top:20px; } #content { background-color:#FFF; border:groove; width:790px; float:left; padding-top:30px; margin-top:30px; } #footer { float:left; height:52px; width:790px; } ``` Please tell me where i made mistake .. ``` the diameseion of background image "backgif" = 995x1000 ```

Original source