3

I have a simple menu and I want to place it in the center of the page using css. Here's the menu: http://jsfiddle.net/kSV4K/4/

Here's the Codes, CSS:

ul#menu { margin:0; padding:0; list-style-type:none; }
ul#menu li { position:relative; float:left; border-bottom:4px solid #efefef; margin-right: 0px; padding-right: 0px; padding-bottom: 5px;}
ul#menu .current { border-bottom:4px solid #3d496a;}
ul#menu li:hover { border-bottom:4px solid #3d496a;}
ul#menu li a { padding:2px 2px; text-decoration:none; font:bold 8px Verdana, Georgia, "Times New Roman", Times, serif; color:#68759c;}
ul#menu li a:hover { color:#8895b8; border:none; }

HTML:

<ul id="menu">
    <li class="current"><a href="#" data-id="div1">Description</a></li>
    <li><a href="#" data-id="div2">Shipping and payment</a></li>
    <li><a href="#" data-id="div3">Returns</a></li>
    <li><a href="#" data-id="div4">Feedback</a></li>
</ul>

Any suggestions?

4

2 回答 2

4

代替浮动,在li元素上使用内联块,然后它们可以居中应用text-align: centerul块上。

ul#menu {
    margin:0;
    padding:0;
    list-style-type:none;
    text-align: center;
}
ul#menu li {
    display: inline-block;
    border-bottom:4px solid #efefef;
    margin-right: 15px;
    padding-right: 20px;
    padding-bottom: 5px;
}

见小提琴:http: //jsfiddle.net/audetwebdesign/kSV4K/3/

于 2013-06-12T15:07:11.980 回答
1

您还可以为菜单添加一些宽度并将其应用margin: 0 auto;到中心这里是小提琴http://jsfiddle.net/xtatanx/swT4F/我还建议您的菜单包含在<nav>标签或<div>.

于 2013-06-12T15:09:51.010 回答