如何在导航栏中将链接右侧对齐

时间:2014-11-12 17:00:34

标签: html css twitter-bootstrap

我有以下代码,我想要的是将右侧的注销按钮和三个模块(联系我们,关于epm和模块)对齐在中心,那么如何在bootstrap的帮助下完成此操作。谢谢提前。

<div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="home.jsp" style="color:purple;cursor: auto" id="wel">Welcome Admin</span></a>
    </div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="about_epm.jsp">About EPM</a></li>
        <li><a href="contact_us.jsp">Contact Us</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Modules <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu"> 
            <li><a href="#">Employer Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Employee Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Client Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Project Details</a></li>
          </ul>
        </li>

    <li>
        <a onClick="logout();" class="navbar-brand pull-right">
            <span class="glyphicon glyphicon-off" id="icon"> Logout</span>  
        </a>
    </li>

    </ul>   
</div>
</div>

1 个答案:

答案 0 :(得分:1)

要右对齐logout对象,可以使用bootstrap的navbar-right类。

要将其他链接居中对齐,您可以使用以下CSS:

#bs-example-navbar-collapse-1 { text-align:center; }
.centered-navbar { display:inline-block; float:none; vertical-align:top; }

HTML

<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="home.jsp" style="color:purple;cursor: auto" id="wel">Welcome Admin</a>
      </div>

      <ul class="nav navbar-nav centered-navbar">
        <li class="active"><a href="about_epm.jsp">About EPM</a></li>
        <li><a href="contact_us.jsp">Contact Us</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Modules <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu"> 
            <li><a href="#">Employer Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Employee Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Client Section</a></li>
            <li class="divider"></li>
            <li><a href="#">Project Details</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
          <a onclick="logout();">
            <span class="glyphicon glyphicon-off" id="icon"> Logout</span>  
          </a>
        </li>
      </ul> 
    </div>
  </div>
</nav>

Bootply在这里:http://www.bootply.com/ddmUGfX0PI