turntabletux Posted December 9, 2007 Share Posted December 9, 2007 Hi,I am trying to create a Div that will be centered on the page, no matter what size the browser window is. Now should I be assigning a % somewhere in my CSS syntax or somewhere else? I know this is very simple, but I am still a little stumped and I'm very anal about my pages. Any help would be greatly appreciated, Thanks in advanced!. Link to comment Share on other sites More sharing options...
Ingolme Posted December 9, 2007 Share Posted December 9, 2007 To center a <div> you can just do this:<body style="text-align: center"><div style="margin: 0 auto; width: 500px;">Some content</div></body>You can also do this (make the "left" property half of [100 - (width)]):<div style="width: 60%; left: 20%">Some content</div> Link to comment Share on other sites More sharing options...
MrAdam Posted December 10, 2007 Share Posted December 10, 2007 Building on Ingolme's example:CSS: body{ text-align:center;}.center{ width: 500px; text-align:left; margin:0px auto;} HTML: <div class="center">....</div> Using "margin:0px auto;" (requires the width to be set) centers the element in most browsers. But also using "text-align:center;" in the body and "text-align:left;" in the .center div centers the element in IE. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.