Jump to content

Another Positioning Question


turntabletux
 Share

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...