Btown2 Posted July 12, 2008 Share Posted July 12, 2008 was wondering if anyone could explain why my container div wont center? my book says this should work but its not in IE7. body { margin: 0; padding: 0; } div { border: 1px solid #000; padding: 20px; margin: 10px; background: #fff; } #container { margin: 0 auto; width: 750px; padding: 20px; border: 1px solid #000; background: #CCC; } .box { margin: 10px; padding: 20px; border: 1px solid #000; background: #09f; width: 75%; } .box p { color: #00f; font-size: 2em; } heres the markup <html> <head> <title>Testing css</title> <link rel="stylesheet" type="text/css" href="css.css"> </head> <body> <div id="container"> <p>content</p> <div class="box"> <p>im in a box</p> </div> <div class="box"> <p>me 2</p> </div> <div> <p>im boxed?</p> </div? </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/114374-solved-div-not-centering/ Share on other sites More sharing options...
xtopolis Posted July 12, 2008 Share Posted July 12, 2008 In your CSS add these on to the existing rules: body { text-align: center; } #container { text-align: left; } Enjoy. Link to comment https://forums.phpfreaks.com/topic/114374-solved-div-not-centering/#findComment-588155 Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 add doctype on begining of the page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> enjoy.... Link to comment https://forums.phpfreaks.com/topic/114374-solved-div-not-centering/#findComment-588167 Share on other sites More sharing options...
Btown2 Posted July 12, 2008 Author Share Posted July 12, 2008 wow, thnx for the speedy replies guys. Link to comment https://forums.phpfreaks.com/topic/114374-solved-div-not-centering/#findComment-588172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.