我需要在 bootstrap 中完整的右对齐导航栏,但问题是我的品牌在左侧,但我需要将其移到右侧。虽然我可以使用navbar-right选项将其他列表项放在右侧。

  <nav class="navbar navbar-default" role="navigation">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
          <button type="button" class="navbar-toggle" 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 pull-right" href="#">CesaStack</a>
      </div>

      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav navbar-right">
              <li class="active"><a href="#">Link</a></li>
              <li><a href="#">Link</a></li>
              <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                  <ul class="dropdown-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>
                      <li class="divider"></li>
                      <li><a href="#">One more separated link</a></li>
                  </ul>
              </li>
          </ul>
          <form class="navbar-form navbar-left" role="search">
              <div class="form-group">
                  <input type="text" class="form-control" placeholder="Search">
              </div>
              <button type="submit" class="btn btn-default">بیاب</button>
          </form>
          <ul class="nav navbar-nav navbar-right">
              <li><a href="#">Link</a></li>
              <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                  <ul class="dropdown-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><!-- /.navbar-collapse -->
  </nav>

最佳答案

将品牌移到navbar-header上方,并为其指定类别navbar-right。

在桌面 View 中,这会使您的品牌位于右侧,而在移动设备 View 中,这会使您的品牌向左移动,从而使菜单按钮保持在最右边。

http://jsfiddle.net/KHtU4/

<nav class="navbar navbar-default" role="navigation">
  <a class="navbar-brand navbar-right" href="#">CesaStack</a>
  <div class="navbar-header">
      <button type="button" class="navbar-toggle" 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>
  </div>

  <div class="collapse navbar-collapse">
      <!-- snip -->
  </div>
</nav>

关于html - 如何在Twitter bootstrap 中将navbar品牌置于右侧?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20568473/

10-11 23:43