无法使搜索框在引导程序导航栏中居中

时间:2017-07-07 18:42:58

标签: html css twitter-bootstrap

我有静态引导程序导航栏,我试图将搜索框放在其中。我尝试的一切都没有用。要么是在导航栏下方,要么根本没有。我现在显示它,但它显示在左侧导航栏标题上方,而不是与其他导航栏项目处于同一垂直位置。我尝试过使用form,navbar-center和现在的div。他们都没有工作。必须有一些简单的bootstrap类或css我不见了。

    <nav class="navbar navbar-default ">
        <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="index.html"><img src="static/img/CAP-Seal-75x75.png" width=50 height=50 ></a>
            <p style="padding-top:25px;width:120%;"></span>CAWG (TRACS) </p>
        </div>
        <div id="search" class="nav navbar-nav navbar-center">
        <form class="nav navbar-nav navbar-center" role="search">
            <input type="text" class="search form-control input-sm" placeholder="Search" id="sitesearch">
                <button type="submit" class="btn btn-xs"><span class="glyphicon glyphicon-search"></span></button>
                </form>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right" style="padding-right:20px;">
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="glyphicon glyphicon-th-list" aria-hidden="true" style="font-size:1.5em;"></span><i class="icon-angle-down"> </i></a>
                    <ul class="dropdown-menu">
                        <li><a href="#track_modal_realtime"  data-toggle="modal">Real Time Tracking</a></li>
                        <li><a id="stop_tracking" href="#">Stop Tracking</a></li>
                        <li><a href="#track_modal_historical"  data-toggle="modal">Historical Tracking</a></li>
                        <li><a href="#send_message_modal"  data-toggle="modal">Communications</a></li>
                    </ul>
                </li>
                <li>
                    <a class="navbar-brand" href="#menu-toggle" id="menu-toggle"><span class="glyphicon glyphicon-resize-full" aria-hidden="true" id="sizeIcon" style="font-size:1.5em;"></span></a></li><!---->
                <li><a href="#settings_modal" data-toggle="modal"><span class="glyphicon glyphicon-cog" style="font-size:1.5em;" aria-hidden="true"></span></a></li>
            </ul>

        </div>
    </nav>

有什么建议吗?

由于

1 个答案:

答案 0 :(得分:0)

希望我已经正确地阅读了你的问题。如果是这样,你总是可以这样做:

   <nav class="navbar navbar-default ">
 <div class="row">
   <div class="col-sm-4">
    <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="index.html"><img src="static/img/CAP-Seal-75x75.png" width=50 height=50 ></a>
        <p style="padding-top:25px;width:120%;"></span>CAWG (TRACS) </p>
    </div>
  </div>
  <div class="col-sm-4">
    <div id="search" class="nav navbar-nav navbar-center">
      <form class="nav navbar-nav navbar-center" role="search">
        <div class="input-group">
          <input type="text" class="search form-control input-sm" placeholder="Search" id="sitesearch">
          <span class="input-group-addon" id="basic-addon2"><span class="glyphicon glyphicon-search"></span></span>
        </div>
      </form>
    </div>
  </div>
  <div class="col-sm-4">
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav navbar-right" style="padding-right:20px;">
        <ul class="nav navbar-nav">
          <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="glyphicon glyphicon-th-list" aria-hidden="true" style="font-size:1.5em;"></span><i class="icon-angle-down"> </i></a>
            <ul class="dropdown-menu">
              <li><a href="#track_modal_realtime"  data-toggle="modal">Real Time Tracking</a></li>
              <li><a id="stop_tracking" href="#">Stop Tracking</a></li>
              <li><a href="#track_modal_historical"  data-toggle="modal">Historical Tracking</a></li>
              <li><a href="#send_message_modal"  data-toggle="modal">Communications</a></li>
            </ul>
          </li>
          <li>
            <a class="navbar-brand" href="#menu-toggle" id="menu-toggle"><span class="glyphicon glyphicon-resize-full" aria-hidden="true" id="sizeIcon" style="font-size:1.5em;"></span></a></li><!---->
          <li><a href="#settings_modal" data-toggle="modal"><span class="glyphicon glyphicon-cog" style="font-size:1.5em;" aria-hidden="true"></span></a></li>
        </ul>
        </div>
    </div>
  </div>
</nav>

通过在cols中使用bootstraps,您可以通过简单地将导航分成3个部分来轻松地居中元素。

希望这就是你所追求的:)

此处的工作示例 - https://codepen.io/anon/pen/ZyMZrY