折叠的引导导航栏中的全宽输入

时间:2017-03-08 08:08:48

标签: jquery css twitter-bootstrap twitter-bootstrap-3

我修改了bootstrap导航栏,将崩溃断点从768px更改为992px。这是我使用过的解决方案:stackoverflow.com/questions/18192082/bootstrap-3-navbar-collapse

问题:在以下条件下搜索输入不是全宽

1)屏幕尺寸介于768px& 992px

2)崩溃被切换

我试过了width 100%&在stackoverflow上找到许多其他建议。这是一个demo on codepen

期望(https://ibb.co/mwx4Qa),现实(https://ibb.co/jZAfyv

HTML

<div class="navbar navbar-inverse navbar-static-top">
  <div class="container">

    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mynav" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>

    <div class="collapse navbar-collapse" id="mynav">
      <ul class="nav navbar-nav navbar-right">
          <li><a href="#link1">Link 1</a></li>
        <form class="navbar-form navbar-left">
          <div class="input-group">
            <input type="text" class="form-control" name="q" placeholder="Search Google">
            <span class="input-group-btn"><button type="submit" class="btn btn-primary">Search</button></span>
          </div>
        </form>
      </ul>
    </div>

  </div>
</div>

2 个答案:

答案 0 :(得分:1)

容器div是给出导航栏宽度的东西,所以如果删除它,它应该可以工作:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<div class="navbar navbar-inverse navbar-static-top">

  <div class="navbar-header">
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mynav" aria-expanded="false">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>

  <div class="collapse navbar-collapse" id="mynav">
    <ul class="nav navbar-nav navbar-right">
        <li><a href="#link1">Link 1</a></li>
      <form class="navbar-form navbar-left">
        <div class="input-group">
          <input type="text" class="form-control" name="q" placeholder="Search Google">
          <span class="input-group-btn"><button type="submit" class="btn btn-primary">Search</button></span>
        </div>
      </form>
    </ul>
  </div>
</div>

答案 1 :(得分:0)

在样式表的底部添加此代码。在您的codepen上测试过。

@media (min-width: 768px) and (max-width: 991px) {
  .navbar-form .input-group .input-group-btn {
    width: 1%;
  }
}