Bootstrap导航栏上的文本输入

时间:2016-07-19 17:38:26

标签: html twitter-bootstrap navbar

我使用Bootstrap制作导航栏,当我尝试添加搜索栏时,它会低于其他元素而不是旁边的元素。

我在所有内容之后导入了jQuery和Bootstrap JavaScript,以及在head标记中导入的Bootstrap CSS。



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<div class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <a class="navbar-brand" href="#"><img src="logo.png"></a>
      <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Home</a></li>

          <form class="navbar-form">
            <input type="text" class="form-control" placeholder="Search">
            <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
         </form>
       </ul>
     </div>
   </div>
 </div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:4)

the result

  1. 您可以使用Default navbar作为样本。
  2. 将表单放在<ul></ul>块之外。
  3. &#13;
    &#13;
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    
    <div class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <a class="navbar-brand" href="#"><img src="logo.png"></a>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#">Home</a></li>
          </ul>
          <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
          </form>
        </div>
      </div>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    &#13;
    &#13;
    &#13;