Page is a not externally linkable
- Code, Content, and Presentation
-- CSS
---- centering a div


limbo - 8:59 am on Oct 23, 2012 (gmt 0)


#centered {
width: 960px;
margin-right: auto;
margin-left: auto;
}


That's exactly right - to center horizontally - you specify automatic left and right margins and a width.

A couple of things to note, you should try and use ID's that better describe the content, not how it is styled. So if it was navigation you want to centre in a you might want to use HTML/CSS like so


<div id="navigation">[Content to be centred]</div>

#navigation {width: 960px;margin:0 auto;}

(note you can combine margin properties)


Thread source:: http://www.webmasterworld.com/css/4511025.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com