从扩展中修复Bootstrap导航栏链接

时间:2015-11-26 22:41:22

标签: html css twitter-bootstrap responsive-design navbar

当我调整浏览器大小时,导航栏链接说“" FIX"下拉到一列。有谁知道如何防止这种情况并将链接保持在同一条线上?

以下是codepen:http://codepen.io/anon/pen/VvJXNw

<!-- navbar -->
<nav class="navbar navbar-default">
  <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" aria-expanded="false">
        <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="#">
        <div class="logo"><img style="width: 21px" src="logo" /></div>
      </a>
    </div> <!-- end of navbar header -->


    <!-- these links dont stay on the same line -->
    <ul class="nav navbar-nav pull-left">
      <li><a id="<%= @users ? 'active-page' : ''%>" href="/">FIX</a></li>
      <li><a id="<%= @users ? 'active-page' : ''%>" href="/">FIX</a></li>
      <li><a id="<%= @about ? 'active-page' : ''%>" href="/">FIX</a></li>
    </ul>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

      <ul class="nav navbar-nav navbar-right">
        <li><a href="/">Sign up</a></li>
        <li><a href="/">Sign in</a></li>
      </ul>

      <form class="navbar-form navbar-right hidden-xs hidden-sm" role="search">
        <div class="form-group">
          <div class="search">
            <span class="fa fa-search"></span>
            <input type="text" class="form-control" placeholder="Search">
          </div>
        </div>
      </form>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

2 个答案:

答案 0 :(得分:2)

您需要将这些链接放在navbar-header内,然后您可以使用navbar-btn之类的帮助程序来定位。也不要使用pull- *,使用navbar-leftnavbar-right。请参阅Docs

请参阅工作示例摘录。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" aria-expanded="false"> <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="#">
        <img alt="" src="/" />
      </a>

      <div class="nav navbar-left"> <a href="#" id="<%= @about_page ? 'active-page' : ''%>" class="btn btn-link navbar-btn">Some Link</a>
        <a href="#" id="<%= @about_page ? 'active-page' : ''%>" class="btn btn-link navbar-btn">Some Link</a>
        <a href="#" id="<%= @about_page ? 'active-page' : ''%>" class="btn btn-link navbar-btn">Some Link</a>

      </div>
    </div>
    <div class="collapse navbar-collapse" id="bs-nav">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#/signup">Sign up</a>

        </li>
        <li><a href="#/login">Sign in</a>

        </li>
      </ul>
      <form class="navbar-form navbar-right hidden-sm hidden-xs" role="search">
        <div class="form-group">
          <div class="input-group"> <span class="input-group-addon" id="basic-addon1"><i class="fa fa-search"></i></span>

            <input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
          </div>
        </div>
      </form>
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

不要在左侧导航栏中使用。 在自定义引导程序导航栏中,默认样式位于左侧。 如果您想使用两侧,只需在导航栏右侧添加导航栏。

Bootstrap navbar with form

Demo here: