0

如何在导航栏中将列表项居中,列表项的宽度不同?谢谢

<div class="wrapper" style="width:100%">
<div class="nav" style="width:100%">
    <ul>
        <li><a href="#">HOME</a></li>
        <li><a href="#">PROJECTS</a></li>
        <li><a href="#">TOURS</a></li>
        <li><a href="#">VOLUNTEER</a></li>
    </ul>
</div>
</div>
4

2 回答 2

2

试试这个

.nav ul {text-align: center;}
.nav ul li {display: inline-block; *display: inline; *zoom: 1; border: 1px solid #999; background: #ccc; padding: 5px;}​​
.nav ul li a {text-decoration: none;}

你给了一个</nav>,实际上是</div>。更正后的HTML

<div class="wrapper" style="width:100%">
    <div class="nav" style="width:100%">
        <ul>
            <li><a href="#">HOME</a></li>
            <li><a href="#">PROJECTS</a></li>
            <li><a href="#">TOURS</a></li>
            <li><a href="#">VOLUNTEER</a></li>
        </ul>
    </div>
</div>​

希望这可以帮助。看看小提琴!:)

于 2012-06-23T04:03:33.303 回答
1

try

.nav ul{text-align:center;}

if that doesn't work, try

.nav ul {width:100%; overflow:hidden;} .nav ul li{position:relative;margin:0px auto;}

于 2012-06-23T03:57:51.193 回答