居中导航栏

时间:2016-05-19 01:29:11

标签: html css

基本上,我希望我想让这个导航栏居中在屏幕中间并且li分别居中

HTML

<div class="navbar">
<ul class="nav">
    <li class="nav"><a class="nav" href="ts3server://ts.santosrp.com/">TeamSpeak</a></li>
    <li class="nav"><a class="nav" href="steam://connect/149.202.89.20:27015">US Server</a></li>
    <li class="nav"><a class="nav" href="steam://connect/158.69.123.91:27015">EU Server</a></li>
</ul>

CSS

    ul.nav{
    display: block;
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
    text-align: center;
    height: 3.3em;
}

li.nav{
    float: left;
}

li a.nav{
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

1 个答案:

答案 0 :(得分:1)

对于li.nav,删除float:left;并使用此:

li.nav{
display: inline-block;
}

&#13;
&#13;
ul.nav{
    display: block;
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
    text-align: center;
    height: 3.3em;
}

li.nav{
display: inline-block;
}

li a.nav{
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}
&#13;
<div class="navbar">
<ul class="nav">
    <li class="nav"><a class="nav" href="ts3server://ts.santosrp.com/">TeamSpeak</a></li>
    <li class="nav"><a class="nav" href="steam://connect/149.202.89.20:27015">US Server</a></li>
    <li class="nav"><a class="nav" href="steam://connect/158.69.123.91:27015">EU Server</a></li>
</ul>
&#13;
&#13;
&#13;