2012-11-18 69 views
0

我的导航栏有以下代码,无法将其集中在网站上。我究竟做错了什么?去除浮动:左边没有任何定位。 谢谢。无法居中我的导航栏

CSS

ul#list-nav { 
    list-style: none; 
    margin: 20px auto; 
    padding: 0px; 
    width: 800px; 
} 

ul#list-nav li { 
    display: inline; 
} 

ul#list-nav li a { 
    text-decoration: none; 
    padding: 5px 0; 
    width: 100px; 
    float: left; 
    background: #485e49; 
    color: #eee; 
    text-align: center; 
    border-left: 1px solid #fff; 
} 

ul#list-nav li a:hover { 
    background: #a2b3a1; 
    color: #000 
} 

HTML

</head> 
<body> 
    <div id="as"> 
     <ul id="list-nav"> 
      <li><a href="#">Home</a></li> 
      <li><a href="#">About Us</a></li> 
     </ul> 
    </div> 
</body> 
+1

请考虑提供[小提琴](http://jsfiddle.net)。 – Sampson

回答

0

它已经集中,它只是你正在使用显式宽度您菜单,以便考虑降低菜单的宽度

Demo

CSS

ul#list-nav { 
    list-style:none; 
    margin:20px auto; 
    padding:0px; 
    width:800px; 
    border: 1px solid #ff0000; 
    overflow: hidden; 
} 

目前我做了它205px

CSS

ul#list-nav { 
    list-style:none; 
    margin:20px auto; 
    padding:0px; 
    width:205px; 
    border: 1px solid #ff0000; 
    overflow: hidden; 
} 

Fixed demo

+0

谢谢你是对的。现在它工作正常。 – user1831677

+0

@ user1831677欢迎您:) –

0

您将需要添加显示:块;

0

你需要用你的导航栏在一个包装DIV,然后该分区的边距设置为自动,像这样:

<style> 
#wrapper { 
margin: auto; 
} 
</style> 

<div id="wrapper"> 

<!-- (your nav bar code here) --> 

</div> 
0

我相信下面的应该做的伎俩;

<格ID = "作为" ALIGN = "中心" >