Centering CSS Menu
I receive this question relatively often: “how to center a menu generated with css menu generator”. Well, here are two examples - one for centering the menu on page and one for centering menu items. For both examples — I am using simple menu saved directly as xhtml file.
A) centering the menu on page
1) Put the menu in new DIV container (in this example - container class=”wrapper”):
<div class=”wrapper“>
<div class=”pd_menu_01 “>
<ul>
…
</ul>
</div>
</div>
2) in the css section, add this code to center the wrapper div:
.wrapper {
width: 80%;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
B) Centering the text of the menu items
To center the text of the menu sub-items, just change the following css code:
.pd_menu_01 ul {list-style-type:none;padding:0; margin:0;}
to:
.pd_menu_01 ul {list-style-type:none;padding:0; margin:0; text-align:center;}
Tags: centering menu, css, css menu
November 7th, 2008 at 4:31 am
Hello,
I don’t really understand why you you add width: 80%; for your wrapper.
Most of time menu have to cover all the width of the #page, not less ?
November 11th, 2008 at 1:33 pm
Ok, I suppose that if we want to center something inside something, the first something should be smaller than the second one, and probably that’s why I made the wrapper smaller… But note that this is just an example, 3 examples, in fact. Nothing more…