Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter bootstrap -- center brand in nav bar

Is there a way I can center the brand name in the nav-bar

My current code is like

<div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
            <ul class="nav pull-left">
                <li>    <button  class="btn btn-primary"> < Back </button> </li>
            </ul>
                <p class="brand"> Report </p> 

                <ul class="nav pull-right">
                    <li>   <button class="btn btn-primary pull-right"> New Report </button>  </li>
                </ul>
        </div>
      </div>
    </div>
like image 320
Anand Sunderraman Avatar asked Jul 16 '12 12:07

Anand Sunderraman


4 Answers

The above answer will not work with version 2 (responsive design):

Instead wrap your brand inside a div:

<div class="brand">
    <a href="/">YOUR BRAND</a>
</div>

And redefine the .brand style in your overrides stylesheet:

.brand
{
    position: absolute;
    width: 100%;
    left: 0;
    text-align: center;
    margin: auto;
}
like image 148
George Filippakos Avatar answered Sep 22 '22 20:09

George Filippakos


Couple ways to center, you might have to try each:

Setting auto-margins:

.brand { margin-left: auto; margin-right: auto; }

Or using a known width (200px example) of an absolute positioned element:

.brand { left: 50%; margin-left: -100px; }
like image 43
Terry Avatar answered Sep 23 '22 20:09

Terry


Finally got it working (checked perfectly by me )

HTML is :

<div class="navbar navbar-fixed-top center" >
<div class="navbar-inner">
    <ul class="nav">
        <li><a href="#">Doctors List</a></li>
    </ul>
</div>

CSS is :

.center.navbar .nav,
.center.navbar .nav > li {
    float:none;
    display:inline-block;
    *display:inline; /* ie7 fix */
    *zoom:1; /* hasLayout ie7 trigger */
    vertical-align: top;
}
.center .navbar-inner {
    text-align:center;
}
like image 26
Abhishek Goel Avatar answered Sep 19 '22 20:09

Abhishek Goel


<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>
    </div>
    <a class="navbar-brand" href="#"> <img src="img/logo.png"></a> <!-- move here your logo -->
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li><a href="#!"><i class="fa fa-pencil"></i> Crear Post</a></li>
        <li class="dropdown">
          <a href="#!" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li class="dropdown-header">Nav header</li>
            <li><a href="#!">Separated link</a></li>
            <li><a href="#!">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#!">Iniciar Sesión</a></li>
        <li><a href="#!">Registrarse</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>

CSS:

.navbar-brand {
    left: calc(50% - 65.5px); //65.5px It is half the width of my logo.jpg
    position: absolute;
}
like image 44
nicogaldo Avatar answered Sep 19 '22 20:09

nicogaldo