将搜索表单添加到顶部导航栏引导程序

时间:2014-01-08 21:37:44

标签: css twitter-bootstrap

我正在尝试将搜索表单添加到下面显示的顶部导航栏代码中,以便它在Logout链接之前显示一个小空格并与右侧对齐,但它总是出现在注销链接之后或者它将会出现展开导航栏并看起来很糟糕。

有人可以通过告诉我在这里缺少什么来帮助我吗?谢谢你的时间。

主管部分:

<head>
 <link rel="stylesheet" href="css/bootstrap.css"> 
 <script type="text/javascript" src="js/jquery-2.0.3.js"></script>
 <script type="text/javascript" src="js/bootstrap.js"></script>
 <title>Test</title>
</head>

身体部分:

<nav class="navbar navbar-inverse" role="navigation">  
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
      <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="#">Company</a>
  </div>

  <div class="collapse navbar-collapse">
    <ul class="nav navbar-nav">      
      <li><a href="#" class="current">Home</a></li>               
      <li class="active dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Employees <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="#">New Employee</a></li>
              <li class="divider"></li>
              <li class="nav-header">Reports</li>
              <li><a href="#" target="_blank">Employees List</a></li>
            </ul>
      </li>                   
    </ul>

    <ul class="nav navbar-nav navbar-right">    

    <form class="navbar-form" role="search">
        <div class="input-group">
            <input type="text" class="input-small" placeholder="Search" name="srch-term" id="srch-term">
            <div class="input-group-btn">
                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
            </div>
        </div>
    </form> 

      <li><a href="#">Logout</a></li>      
    </ul>
  </div>   
</nav>

1 个答案:

答案 0 :(得分:2)

你不能将<form>放在<ul>内但不包含在<li>中,所以这里似乎有效:

jsFiddle

<nav class="navbar navbar-inverse" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <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="#">Company</a>
    </div>
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            <li>
                <a href="#" class="current">Home</a>
            </li>
            <li class="active dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Employees <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li>
                        <a href="#">New Employee</a>
                    </li>
                    <li class="divider"></li>
                    <li class="nav-header">Reports</li>
                    <li>
                        <a href="#" target="_blank">Employees List</a>
                    </li>
                </ul>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li>
                <a href="#">logout</a>
            </li>
        </ul>
        <form class="navbar-form navbar-right" role="search">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </form>
    </div>
</nav>