bootstrap 3 - how do I place the brand in the center of the navbar?

后端 未结 8 1493
臣服心动
臣服心动 2020-11-30 04:27

I am using Bootstrap 3. I would like a navbar with only the brand in it. No other links or anything else. And I want the brand to be in the center. How can I accomplish t

相关标签:
8条回答
  • 2020-11-30 04:53

    Another option is to use nav-justified..

    <nav class="navbar navbar-default" role="navigation">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>    
      </div>
      <div class="navbar-collapse collapse">
        <ul class="nav nav-justified">
          <li><a href="#" class="navbar-brand">Brand</a></li>
        </ul>
      </div>
    </nav>
    

    CSS

    .navbar-brand {
        float:none;
    }
    

    Bootply

    Alternate example

    0 讨论(0)
  • 2020-11-30 04:59

    I used two classes to achieve this and maintain responsiveness navbar-brand-left and navbar-brand-center. Keep in mind it utilises Sass / Less Bootstrap for line height, otherwise specify a hardcode px / rem height.

    HTML

    <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-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 href="#" class="navbar-brand-left visible-xs visible-sm">Brand</a>
        </div>
    
        <div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li><a href="#">About</a></li>
            <li><a href="#">How it works</a></li>
          </ul>
          <a href="#" class="navbar-brand-center hidden-xs hidden-sm">Brand</a>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Log in</a></li>
            <li><a href="#">Start now</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
    

    CSS

    .navbar-brand-left {
        display: inline-block;
        margin: 0;
        padding: 0;
        line-height: @navbar-height;
    }
    
    .navbar-brand-center {
        display: inline-block;
        margin: 0 auto;
        padding: 0;
        line-height: @navbar-height;
    }
    
    0 讨论(0)
提交回复
热议问题