bootstrap搜索全宽

时间:2015-11-29 23:14:55

标签: css twitter-bootstrap search field

有这个例子。 https://jsfiddle.net/sea2sw25/1/

但始终保持顶级搜索字段,以及767px以下。这是可能的? 搜索字段全宽总是?

谢谢。

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">MAIN</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand hidden-xs" href="">BootStrap</a>
            <a class="navbar-brand visible-xs" href="">B</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a href="about.html">Abount</a>
                </li>
                <li>
                    <a href="services.html">Services</a>
                </li>
                <li>
                    <a href="contact.html">Contact</a>
                </li>

            </ul>
            <form class="navbar-form">
            <div class="form-group" style="display:inline;">
                <div class="input-group" style="display:table;">
                    <input class="form-control" name="search" placeholder="Search" autocomplete="off" autofocus="autofocus" type="text">
                    <span class="input-group-addon" style="width:1%;"><span class="glyphicon glyphicon-search"></span></span>
                </div>
            </div>
            </form>               
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

1 个答案:

答案 0 :(得分:0)

执行此操作的一种方法是将表单放在navbar-header内,以便它始终保持公开状态,然后使用媒体查询来控制表单的宽度,以便它不会覆盖您的链接等

更新:在Firefox41&amp ;;上测试42,Chrome46,Opera32,Edge13和IE11

请参见整页的示例代码段。

&#13;
&#13;
.navbar-custom .navbar-search {
  position: absolute;
  margin-left: 120px;
  margin-top: 8px;
  width: 750px;
}
@media (min-width: 1200px) {
  .navbar-custom .navbar-search {
    max-width: 750px;
  }
}
@media (min-width: 992px) and (max-width: 1199px) {
  .navbar-custom .navbar-search {
    max-width: 550px
  }
}
@media (min-width: 768px) and (max-width: 991px) {
  .navbar-custom .navbar-search {
    max-width: 350px
  }
}
@media (max-width: 767px) {
  .navbar-custom .navbar-search {
    margin-left: 50px;
    padding-right: 125px;
    max-width: 700px;
    width: 100%;
  }
  .navbar-custom .navbar-toggle {
    z-index: 1060;
  }
}
&#13;
<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 navbar-custom" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-nav"> <span class="sr-only">MAIN</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      </button> <a class="navbar-brand " href="">B<span class="hidden-xs">ootStrap</span></a>

      <form class="navbar-search">
        <div class="form-group">
          <div class="input-group">
            <input class="form-control" name="search" placeholder="Search" autocomplete="off" autofocus="autofocus" type="text"> <span class="input-group-btn"> <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span>

            </button>
            </span>
          </div>
        </div>
      </form>
    </div>
    <div class="collapse navbar-collapse" id="bs-nav">
      <ul class="nav navbar-nav navbar-right">
        <li> <a href="about.html">Abount</a>

        </li>
        <li> <a href="services.html">Services</a>

        </li>
        <li> <a href="contact.html">Contact</a>

        </li>
      </ul>
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;