宽幅导航栏形式输入组-引导程序3

时间:2018-11-01 21:30:38

标签: css twitter-bootstrap-3

在台式机版本的导航栏中,我无法使输入字段的流体宽度达到100%。

<nav class="navbar navbar-inverse navbar-fixed-top">
 <div class="container-fluid">
  <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
        <span class="sr-only">Menu</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#"><img src="https://via.placeholder.com/100x30.png?text=Logo" width="100" height="25" /></a>
  </div>
  <div id="navbar" class="navbar-collapse collapse">
    <div class="nav navbar-nav">
      <div class="navbar-form">
        <div class="input-group">
          <input type="url" class="form-control" placeholder="http://www.website.com" name="url" value="" />
          <span class="input-group-btn">
            <button class="btn btn-success" type="button" id="seo-submit">Submit</button>
          </span>
        </div>
      </div>
    </div>
    <ul class="nav navbar-nav navbar-right">
      <li>
        <a href="#">Item 1</a>
      </li>
      <li>
        <a href="#">Item 2</a>
      </li>
      <li>
        <a href="#">Item 3</a>
      </li>
    </ul>
  </div>
 </div>
</nav>

在此处也创建了Codeply链接:https://www.codeply.com/go/IsKEVDDCkG

有什么想法可以使输入栏和按钮填满导航栏空间,同时保持内联?

1 个答案:

答案 0 :(得分:1)

您将需要对CSS和HTML进行一些更改。

在HTML上,我将类navbar-left添加到菜单div中。 现在在CSS上,我们可以使用一些flexbox属性来使每件事变得更加流畅。

我使用媒体查询进行了编码,因此您需要添加它们,以便您的移动布局保持完整。

整页中测试此代码段

div#navbar {
      display: flex!important;
}

.navbar-left{
    flex-grow: 1;
}
      
.navbar-nav {
      float: none!important;
    }

.navbar-form .input-group,
.navbar-inverse .navbar-form,
.input-group-btn:last-child>.btn{
     width: 100%; 
     
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

 <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
            <span class="sr-only">Menu</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#"><img src="https://via.placeholder.com/100x30.png?text=Logo" width="100" height="25" /></a>
      </div>
      <div id="navbar" class="navbar-collapse collapse">
        <div class="nav navbar-nav navbar-left">
          <div class="navbar-form">
            <div class="input-group">
              <input type="url" class="form-control" placeholder="http://www.website.com" name="url" value="" />
              <span class="input-group-btn">
                <button class="btn btn-success" type="button" id="seo-submit">Submit</button>
              </span>
            </div>
          </div>
        </div>
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="#">Item 1</a>
          </li>
          <li>
            <a href="#">Item 2</a>
          </li>
          <li>
            <a href="#">Item 3</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>

希望这会有所帮助:)