当Bootstrap响应时,如何更改导航栏位置

时间:2013-12-04 17:27:26

标签: html css twitter-bootstrap responsive-design

网站的桌面视图下方有徽标和导航 当切换到移动视图时,我希望导航的位置变为徽标上方(并在徽标和导航栏之间创建一个小空间)。

这是桌面视图:

desktop

移动视图:

mobile

我希望移动视图

how I want mobile


HTML:

    <div class="text-center logo">
        <a href="index.html"><img src="img/brand.png" /></a>
        <span class="brand-headline visible-desktop">
            <p class="title-text">Example</p>
        </span>
    </div>

<!-- =begin navigation !-->
    <nav class="navbar navbar-default" role="navigation">
    <div class="container">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-target">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <span class="navbar-brand brand" href="#">Brand</span>
      </div>

      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="navbar-target">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Schuhe</a></li>
          <li><a href="#">Link</a></li>
      </div><!-- /.navbar-collapse -->
      </div>
    </nav>

3 个答案:

答案 0 :(得分:8)

直到我对FlexBox的支持更多,我这样做是用jQuery克隆它。我一直这样做,因为无论如何BS3菜单都需要jQuery。

演示: http://jsbin.com/oVifowe/1/

/* __________________ Mobile Menu __________________*/
 $(document).ready(function() {

 $('.navbar').clone().removeClass('hidden-xs').appendTo('.mobile-menu');

 }); //end

HTML:

 <div class="mobile-menu visible-xs"><!--MENU CLONES HERE--></div>

 <div class="text-center logo">
    <a href="index.html"><img src="img/brand.png" /></a>
    <span class="brand-headline visible-desktop">
        <p class="title-text">LOGO</p>
    </span>
</div>

<!-- begin navigation !-->
<nav class="navbar navbar-default hidden-xs" 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="#navbar-target">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="navbar-target">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Schuhe</a></li>
      <li><a href="#">Link</a></li>
  </div><!-- /.navbar-collapse -->
  </div>
</nav>

答案 1 :(得分:4)

@media(max-width: 767px) {
  .navbar.navbar-default {
     position:fixed; top:0; left:0; z-index:1030;
   }
}

您可能还想在平板电脑和更小的平板电脑上添加顶部填充到主体或主包装。

答案 2 :(得分:1)

您可以将导航的位置固定在小型设备上。除此之外,您可能必须切换不同版本的模板,因为您正在更改html流的顺序。