Bootstrap 3.1.1导航栏最大化输入不再在3.2.0中最大化

时间:2014-07-06 05:23:11

标签: html css twitter-bootstrap

问题:如何在Bootstrap 3.2.0导航栏中获得最大化的搜索输入?

在Bootstrap 3.1.1中,我将以下代码用于固定的底部导航栏,以显示最大化的搜索输入。

<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>

它看起来像这样: Picture of maximized search using Bootstrap 3.1.1

升级到Bootstrap 3.2.0后,我的导航栏看起来像这样: Picture of small search using Bootstrap 3.2.0

3 个答案:

答案 0 :(得分:6)

只需添加到自定义css文件:

.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%;
}

答案 1 :(得分:3)

我从3.1.1升级到3.2.0时遇到了同样意想不到的经历 - 我的(顶部)导航栏形式过去占据了屏幕的全宽,现在只是一个短元素。这对我的自定义CSS有用,在Boostrap之后加载(这是我如何覆盖Bootstrap,同时保留其原始的干净缩小版本):

/* 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%;
}

答案 2 :(得分:1)

编辑:forms.less from bootstrap 3.2

取消注释第411和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
  }
}