7

Question: How can I get a maximized search input in a Bootstrap 3.2.0 nav bar?

In Bootstrap 3.1.1 I used the following code for a fixed bottom nav bar to display a maximized search input.

<nav class="navbar navbar-default navbar-fixed-bottom" role="seasrch">
    <div class="container">
        <form class="navbar-form">
            <div class="form-group">
                <div class="input-group input-group-sm">
                    <div class="input-group-btn">
                        <a href="#" id="new_term" class="btn btn-default" role="button"><span class="glyphicon glyphicon-leaf"></span>&nbsp;&nbsp;New</a>
                        <a href="/terms.php" class="btn btn-default" role="button"><span class="glyphicon glyphicon-tree-deciduous"></span>&nbsp;&nbsp;All</a>
                    </div>
                    <input type="input" class="form-control" name="search_bar_text" />
                    <div class="input-group-btn">
                        <button class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</nav>

And it looked like this: Picture of maximized search using Bootstrap 3.1.1

My nav bar looks like this, after upgrading to Bootstrap 3.2.0: Picture of small search using Bootstrap 3.2.0

McVenco
  • 1,011
  • 1
  • 17
  • 30
Jay Haase
  • 1,979
  • 1
  • 16
  • 36
  • Seems like a browser quirk: the navbar is unmaximized with Firefox 30.0/Bootstrap 3.1.1 too. – Pete TNT Jul 06 '14 at 09:22
  • @PeteTNT: Interesting, you are right. It is unmaximized on Firefox, but maximized on Safari and Chrome using 3.1.1. I guess Bootstrap is now more consistent with 3.2.0, and my approach does not work on any browser. :-) – Jay Haase Jul 06 '14 at 15:45

3 Answers3

6

Just add to your custom css file:

.navbar-form .input-group {
    display: table;
}
.navbar-form .input-group .input-group-addon,
.navbar-form .input-group .input-group-btn {
    white-space: nowrap;
    width: 1%;
}
.navbar-form .input-group .form-control {
    width: 100%;
}
Alexey Kosov
  • 3,010
  • 2
  • 23
  • 32
3

I had the same unexpected experience as I upgraded from 3.1.1 to 3.2.0 - my (top) navbar-form which used to take full width of the screen was now just a short element. This is what worked for me in my custom CSS that loads up after Boostrap (that's how I override Bootstrap while preserving their original clean minified version):

/* Boostrap CSS 3.2.0 had these new lines in the navbar-form that
   were different from 3.1.1 [it's all in @media (min-width: 768px)
   so this behavior only shows up on higher resolutions] */
.navbar-form .input-group {
    display: inline-table;
    vertical-align: middle;
}
.navbar-form .input-group .input-group-addon,
.navbar-form .input-group .input-group-btn,
.navbar-form .input-group .form-control {
    width: auto;  /* HERE IS THE CULPRIT */
}
/** SOLUTION: in custom CSS **/
/* make sure navbar-form's input-group goes 100% i.e. full width of screen 
   to compliment the display: inline-table; that showed up in 3.2.0 */
.navbar-form .input-group {
      width: 100%;
}
/* override width: auto; that showed up in 3.2.0
   with at least 1px for the addon or btn (I had an addon) */
.navbar-form .input-group .input-group-addon,
.navbar-form .input-group .input-group-btn {
      width: 1px;
}
/* separate .form-control and give it width: 100%; */
.navbar-form .input-group .form-control {
        width: 100%;
}
tkanzakic
  • 5,499
  • 16
  • 34
  • 41
svet
  • 46
  • 2
  • I have added this to my style, but it doesn't work. Here there is [another thread](https://github.com/twbs/bootstrap/issues/14272) discussing on this issue. – Jimmy Aug 02 '14 at 17:58
1

edit: forms.less from bootstrap 3.2

uncomment line 411 and 422

.form-control {
  display: inline-block;
  // width: auto;  // uncomment by sebush // Prevent labels from stacking above inputs in `.form-group`
  vertical-align: middle;
}

.input-group {
  display: inline-table;
  vertical-align: middle;

  .input-group-addon,
  .input-group-btn,
  .form-control {
    // width: auto;  // uncomment by sebush
  }
}