Hi all - can someone please center this menu for me? Thank you #menu1 { border-top: 1px solid #949494; background-color: #DD6E05; width: 100%; /*haslayout so background colour shows in IE6*/ overflow: hidden; } #header ul li { display: inline; /*some declaration for IE7, otherwise ignore li's*/ z-index:1000 } #header ul a, #header p { float: left; font-family: tahoma; font-size: 11px; color: #e0e4e7; height: 26px; line-height: 26px; text-align: center; text-decoration: none; padding: 0 10px; } #header ul a:focus, #header ul a:hover { background-color: white; color: #DD6E05; } * html #header p {margin-right: -3px;} /*stoopid 3-pixel-jog bug*/ Code (markup):
You might find that a 100% width div will not center in anything as it is display block 100% of the containment area. When you try to center a div like this you will need to fix the width to a pixel dimension: #menu1 { border-top: 1px solid #949494; background-color: #DD6E05; width: 100%; /*haslayout so background colour shows in IE6*/ overflow: hidden; } I would use something like this: #menu1 { border-top: 1px solid #949494; background-color: #DD6E05; width: 160px; /*The width you want the menu to be*/ overflow: hidden; margin:0 auto; }
I love all the responsese that didn't bother looking at the code, because margin is going to do exactly two things - and jack left town, took his **** with him. Why do I say this? Because his UL is set to 100% width, and the anchors are set to FLOAT. Centering a menu filled with FLOATED elements and a dynamic width on it's elements is impossible - doesn't work. Though I have to ask is this a cascading menu, or just a flat inline? CSS without the markup is pretty much useless for determining things like that. Either way, you might want to have a look at this menu example I wrote for someone on the .js forums. (where I pretty much said don't use javascript for a menu except for backwards IE support) http://battletech.hopto.org/html_tutorials/cssMenu/ It relies on Peterned's 'hover anywhere' to bring legacy versions of IE into line, and uses a trick I came up with using word-spacing and letter-spacing to remove unwanted white-space between the LI - which is really the only reason to use the float in the first place