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 this? The following css doesn't work:

.navbar-brand {
    text-align: center;
}
shareimprove this questionasked Nov 16 '13 at 22:01jononomo4,5401257102

5 Answers 正确答案

css:

.navbar-header {
    float: left;
    padding: 15px;
    text-align: center;
    width: 100%;
}
.navbar-brand {float:none;}

html:

<nav class="navbar navbar-default" role="navigation">
  <div class="navbar-header">
    <a class="navbar-brand" href="#">Brand</a>
  </div>
</nav>
shareimprove this answeranswered Nov 17 '13 at 10:23Bass Jobsen40.5k12112193

   Love you boss!! – sforsandeep Sep 25 '14 at 15:4013 This messes with the collapsed navigation menu for me – Tom Oct 21 '14 at 7:402 Having a width of 100% causes the header to overlap the collapsed navigation menu button making it unclickable. Having a narrower and centred navbar-header should stop the overlap leaving the button clickable. – Paul Bullivant Dec 11 '14 at 16:12    If using LESS, you can specify @navbar-padding-vertical instead of padding: 15px;. – XåpplI'-I0llwlg'I - Aug 14 '15 at 3:522 According to the question they dont need navbar-header since they don't have any other links in it. However, for others who do want links either increase the z-index of navbar-toggle or consider this apporach: stackoverflow.com/a/34150526/3123861 – Bryan Willis Dec 8 '15 at 8:01

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

shareimprove this answeredited Oct 3 '16 at 15:21Colin14.8k1072134answered Dec 3 '13 at 22:03ZimSystem123k35262272

   There seems to be a problem when using a mobile? – Cary Bondoc Apr 28 '15 at 8:41   I have fixed that issue in the edits – ZimSystem Mar 11 at 13:47

If you have no other links, then there is no use for navbar-header....

HTML:

<nav class="navbar navbar-inverse navbar-static-top">
    <div class="container">
     <a class="navbar-brand text-center center-block" href="#">Navbar Brand</a>
  .....
</nav>

CSS:

.navbar-brand {
  float: none;
}


However, if you do want other links here's a very effective approach that allows that:https://stackoverflow.com/a/34149840/3123861

shareimprove this answeredited May 23 at 12:34Community♦11answered Dec 8 '15 at 8:09Bryan Willis2,0441825

To fix the overlap, you only need modify the .navbar-toggle in your own css styles

something like this, it works for me:

.navbar-toggle{
z-index: 10;
}
shareimprove this answeranswered Mar 22 '15 at 21:44Gricel Sepúlveda111

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;
}
shareimprove this answeranswered Apr 29 at 2:36Grant1216

来自  https://stackoverflow.com/questions/20024463/bootstrap-3-how-do-i-place-the-brand-in-the-center-of-t...