防止导航栏菜单换行

时间:2015-03-31 12:50:06

标签: css twitter-bootstrap navbar

使用Bootstrap(jsbin here)创建导航栏并重新设置为小的浏览器宽度时,菜单会这样包装:

enter image description here

我们怎样才能让菜单无法包装,并保持一条线?(按钮/搜索字段应该在品牌的顶部,品牌可能会被掩盖)


这是导航栏的代码:

 <nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <a class="navbar-brand" href="#">Brand</a>
      </div>
      <div>
       <ul class="nav navbar-nav navbar-right">
        <li class="navbar-form">
            <div class="form-group">
              <div class="input-group input-group-sm">
                    <input class="form-control" placeholder="Search" type="text">
                    <span class="input-group-btn">
                      <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
                    </span>
              </div>
            </div></li>
          <li><a type="button" class="btn btn-default btn-sm" href="http://gget.it/ornlbhjq/edit.php" id="newpost">New post</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown" role="button" aria-expanded="false" id="dropdown">Login / Signup&nbsp;<span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </nav>

1 个答案:

答案 0 :(得分:0)

因为.navigation中的列表项具有display:block;,因此会自动占用他们可以占用的所有空间。

所以改变

.nav>li {
  position: relative;
  display: block;
}

.nav>li {
  position: relative;
  display: inline-block;
}