Bootstrap导航栏输入字段太窄

时间:2015-11-11 01:52:14

标签: html css twitter-bootstrap layout

我有一个基于bootstrap的html,它看起来像我想要的Bootply,但在我的页面中,查询字段看起来比应该的要窄。我只是不知道出了什么问题。

以下是代码:

<nav class="navbar navbar-inverse 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>
        <a class="navbar-brand" href="#">Link</a>
    </div>

    <div id="navbar" class="navbar-collapse collapse">




        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Welcome <span class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a href="xxx.php">Sair</a></li>
                </ul></li>
        </ul>



        <form class="navbar-form" method="post">
            <div class="form-group" style="display: inline;">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="Busca" name="q"> 
                        <span class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
                </div>
            </div>

        </form>

    </div>


    <!--/.navbar-collapse -->
</div>

这是期望的结果: desired result

这是真实的结果: enter image description here

1 个答案:

答案 0 :(得分:1)

您看到的是默认行为。您可以轻松调整此选项以满足您的需求。为form分配一个新类,添加适当的宽度,您可能需要/需要调整顶部位置。

请参阅整页的工作代码段。

@media (min-width: 768px) {
  .navbar-form-fw {
    width: 95%;
  }
  .input-group.input-group-fw {
    top: 8px;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse 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> <a class="navbar-brand" href="#">Link</a>

    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Welcome <span class="caret"></span></a>

          <ul class="dropdown-menu">
            <li><a href="xxx.php">Sair</a>

            </li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form-fw" method="post">
        <div class="form-group">
          <div class="input-group input-group-fw">
            <input type="text" class="form-control control-form" placeholder="Busca" name="q"> <span class="input-group-addon"><span class="glyphicon glyphicon-search"></span></span>
          </div>
        </div>
      </form>
    </div>
  </div>
</nav>