Bootstrap 4 Alpha 6.搜索框在导航栏崩溃时溢出容器

时间:2017-10-03 16:53:24

标签: html css twitter-bootstrap

我是一个非常新的Bootstrap 4,所以这里可能会有很多错误。

我想创建一个响应式导航栏,它会折叠我的4个菜单按钮,但仍然会将搜索栏保持在右侧。我不确定如何在展开后处理按钮的显示,但我现在的目标是将搜索栏保持在正确的宽度右侧。

当屏幕显示"小"时,导航切换按钮显示,折叠菜单按钮。太酷了。但搜索栏只是从容器中生长出来。如何将其保存在容器中?

我感谢任何建议和改进:)



nav {
  background: brown;
}

nav .container {
  white-space: nowrap;
}

<head>
  <!-- Meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">


  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


  <title>My Site</title>
</head>

<body>



  <nav class="navbar sticky-top navbar-inverse navbar-toggleable-sm">

    <div class="container" style="width:1400px">


      <div class="d-inline-block">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#Navbar">
                    <span class="navbar-toggler-icon"></span>
                </button>
      </div>


      <div class="collapse navbar-collapse" id="Navbar">
        <ul class="navbar-nav">
          <li class="nav-item active">
            <a class="nav-link" href="#">
              <span class="fa fa-home"> Home</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">
              <span class="fa fa-music"> Music</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">
              <span class="fa fa-info"> About</span>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">
              <span class="fa fa-address-card"> Contact Us</span>
            </a>
          </li>
        </ul>
      </div>


      <form class="d-inline-block w-100" role="search">
        <div class="input-group">
          <input type="text" class="form-control" placeholder="Search by artist or album name">
          <span class="input-group-btn">
                        <button class="btn btn-secondary" type="submit">
                            <i class="fa fa-search"></i>
                        </button>
                    </span>
        </div>
      </form>



    </div>
  </nav>
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

</body>
&#13;
&#13;
&#13;

编辑:我调整了一下,得到了以下结果 - &gt; https://jsfiddle.net/Taliesin84/qL35nejo/

我目前的目标是在尺寸变得太小时阻止搜索栏包含折叠按钮。 我还需要在更大的屏幕尺寸中使搜索栏更宽,但现在这是次要的。有什么新想法吗?

1 个答案:

答案 0 :(得分:0)

来自Bootstrap 4&#39; github repo中的示例:

<form class="form-inline my-2 my-lg-0">
  <input class="form-control mr-sm-2" type="text" placeholder="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>