本文介绍了我怎么能集中这个菜单与CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个菜单固定,我如何中心这个菜单?
我已经尝试了margin:0 auto和float:left,但它不工作。
有什么办法可以让中心吗?
这里我有一个演示:
I have this menu fixed, how can I center this menu?
I already tried with margin: 0 auto, and float: left, but it doesn't work.
Are there any way to center ??
here I have a demo:
<nav>
<ul id="main-nav" class="clearfix">
<li><a href="#;">Inicio</a></li>
<li><a href="#">Guia</a></li>
<li><a href="#">Heroes</a></li>
<li><a href="#">Videos</a></li>
<li><a href="#">ScreamShots</a></li>
</ul>
</nav>
CSS
#main-nav {
width: 100%;
margin: 0 auto;
padding: 0;
position: fixed;
left: 0;
/*bottom: 0;*/
z-index: 100;
background: #9dd53a; /* Old browsers */
background: -moz-linear-gradient(top, #9dd53a 26%, #a1d54f 47%, #80c217 67%, #7cbc0a 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(26%,#9dd53a), color-stop(47%,#a1d54f), color-stop(67%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #9dd53a 26%,#a1d54f 47%,#80c217 67%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #9dd53a 26%,#a1d54f 47%,#80c217 67%,#7cbc0a 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #9dd53a 26%,#a1d54f 47%,#80c217 67%,#7cbc0a 100%); /* IE10+ */
background: linear-gradient(to bottom, #9dd53a 26%,#a1d54f 47%,#80c217 67%,#7cbc0a 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */
border-radius: 8px;}
#main-nav li {
position: relative;
margin: 0 auto;
padding: 0;
list-style: none;
float: left;}
#main-nav a {
margin: 0 auto;
line-height: 100%;
font-weight: bolder;
color: #000000;
display: block;
padding: 15px 20px;
text-decoration: none;}
推荐答案
您可以将 #mainnav li
更改为从 float:left;
更改为 display:inline- block;
You can change the #mainnav li
as from float: left;
to display: inline-block;
#main-nav li {
position: relative;
margin: 0 auto;
padding: 0;
list-style: none;
display: inline-block;
}
,然后可以使用text-align:center;在ul上。
and then you can use text-align: center; on the ul.
#main-nav {
...
text-align: center;
...
}
工作演示:
这篇关于我怎么能集中这个菜单与CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!