4

What I'm trying to do is have the search box in the center of the navbar (image here). How would I do that?

HTML:

<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <a class="brand" href="#">logo</a>
      <div class="nav-collapse collapse">
        <form class="navbar-form pull-right">
          <div class="input-append">
            <input class="span4" id="appendedInputButton" type="text" placeholder="Search...">
            <button class="btn" type="button">Search</button>
          </div>
        </form>
      </div><!--/.nav-collapse -->
    </div>
  </div>
</div>

I'm using the default CSS that comes with Bootstrap.

madth3
  • 7,275
  • 12
  • 50
  • 74
Feriscool
  • 61
  • 2
  • 2
  • 5

4 Answers4

2

wrap the form element within its own div and give it a class or an id, then create a custom line of code to center it, example:

HTML:

<div id="search">
*form code here*
</div>

CSS:

#search { width: 200px; margin: auto; }
Andy Holmes
  • 7,817
  • 10
  • 50
  • 83
1

if you need to override built in CSS in an application, use !important like so:

<div style="margin: 0px auto !important;"></div>

Or, put it in your css class.

RandomUs1r
  • 4,010
  • 1
  • 24
  • 44
0

See this...

.nav-collapse{
    margin-right: 50%;
}

Example

MG_Bautista
  • 2,593
  • 2
  • 18
  • 33
0

Struggled with this for a long time too, for Bootstrap 3. I finally found this solution which worked perfectly for me: Bootstrap NavBar with left, center and right aligned items Just added a class to the inside my navbar around my search box, with the css definition in Skelly's answer.

I did then have to apply text-align:left to some of elements in my form (e.g. typeahead suggestions attached to my search form).

Community
  • 1
  • 1
randalv
  • 900
  • 9
  • 19