【问题标题】:bootstrap navbar visible element in between介于两者之间的引导导航栏可见元素
【发布时间】:2015-09-13 03:06:33
【问题描述】:

默认的bootstrap navbar在小屏上只有logo部分可见,navbar的所有正确内容都变成了toggle button。
标志 |菜单 |登录(右对齐)(> 767px)
标志 |切换按钮(右对齐)(包括菜单和登录)(

但是,我想实现如下情况
标志 |菜单 |图标 1、图标 2(右对齐)|登录(右对齐)(> 767px)
标志 |图标 1、图标 2(右对齐)|切换按钮(右对齐)(包括菜单和登录)(

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <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="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Menu 1</a></li>
            <li><a href="#contact">Menu 2</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href=""><i class="fa fa-search"></i></a></li>
            <li><a href=""><i class="fa fa-user"></i></a></li>
            <li><a href="">Log In <span class="sr-only">(current)</span></a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

【问题讨论】:

    标签: css twitter-bootstrap


    【解决方案1】:

    这可能会有所帮助或给您一些想法;它需要一些定制,但效果很好。

    您可以在 columns 之间拆分 navbar 并用包装器将其括起来。

    .wrapper {
      padding-left: 15px;
      padding-right: 15px;
      padding-bottom: 60px;
      margin: 0 auto;
    }
    .wrapper .navbar-default {
      margin: 0px;
      padding: 0px;
      width: 100%;
      position: fixed;
      border-radius: 0px;
    }
    .navbar-default .navbar-collapse {
      background: #f5f5f5;
    }
    .wrapper .login {
      display: inline;
      position: fixed;
      width: 100px;
      right: 65px;
      height: 50px;
      margin: 0px;
      padding: 0px;
      border: transparent;
      border-radius: 0px;
    }
    .wrapper .login i {
      padding: 12px 0;
      margin: 0 auto;
      color: #555;
    }
    .no-gutter >[class*='col-'] {
      padding-right: 0;
      padding-left: 0;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
    <div class="wrapper">
      <div class="row no-gutter">
        <div class="col-xs-9">
          <nav class="navbar navbar-default">
            <!-- 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-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="#">Project Name</a> 
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-nav">
              <ul class="nav navbar-nav">
                <li class="active"><a href="#">Menu 1 <span class="sr-only">(current)</span></a>
    
                </li>
                <li><a href="#">Menu 2</a>
    
                </li>
              </ul>
              <ul class="nav navbar-nav navbar-right">
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Login <span class="caret"></span></a>
    
                  <ul class="dropdown-menu">
                    <li><a href="#">Stuff</a>
    
                    </li>
                  </ul>
                </li>
              </ul>
            </div>
            <!-- /.navbar-collapse -->
          </nav>
          <!--end nav-->
        </div>
        <!--end col9-->
        <div class="col-xs-3">
          <div class="login">
            <a href="#" class="btn"> <i class="fa fa-user"></i>
            </a>
            <a href="#" class="btn"> <i class="fa fa-search"></i>
            </a>
          </div>
        </div>
        <!--end col3-->
      </div>
      <!--end row-->
    </div>
    <!--end wrapper-->
    <div class="container">
      <div class="alert alert-info">Bootstrap</div>
      <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
        one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
        et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
        1.10.32.</p>
      <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
        one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
        et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
        1.10.32.</p>
      <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
        one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
        et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
        1.10.32.</p>
      <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
        one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
        et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
        1.10.32.</p>
    </div>

    【讨论】:

      【解决方案2】:

      你也可以试试这个。

      .icons{
          display: block;
          float: right;
          margin: 0 20px !important;
      }
      .icons li{
          display: inline-block !important;
          
      }
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
      <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
      <!-- Fixed navbar -->
      <nav class="navbar navbar-default navbar-fixed-top">
          <div class="container">
              <div class="navbar-header">
                  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <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="#">Project name</a>
                  <ul class="nav navbar-nav icons visible-xs">
                      <li><a href=""><i class="fa fa-search"></i></a>
                      </li>
                      <li><a href=""><i class="fa fa-user"></i></a>
                      </li>
                  </ul>
      
              </div>
              <div id="navbar" class="navbar-collapse collapse">
                  <ul class="nav navbar-nav">
                      <li class="active"><a href="#">Menu 1</a>
                      </li>
                      <li><a href="#contact">Menu 2</a>
                      </li>
                  </ul>
                  <ul class="nav navbar-nav navbar-right">
                      <li class="hidden-xs"><a href=""><i class="fa fa-search"></i></a>
                      </li>
                      <li class="hidden-xs"><a href=""><i class="fa fa-user"></i></a>
                      </li>
                      <li><a href="">Log In <span class="sr-only">(current)</span></a>
                      </li>
                  </ul>
              </div>
              <!--/.nav-collapse -->
          </div>
      </nav>

      【讨论】:

        猜你喜欢
        • 2014-04-01
        • 2021-04-18
        • 2013-12-06
        • 1970-01-01
        • 2016-11-01
        • 2018-10-28
        • 2015-07-16
        • 2021-03-29
        • 1970-01-01
        相关资源
        最近更新 更多