gpt4 book ai didi

html - Bootstrap 4 Alpha 6.搜索框在导航栏折叠时溢出容器

转载 作者:行者123 更新时间:2023-11-28 02:53:53 25 4
gpt4 key购买 nike

我是 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>

编辑:我稍微调整了一下,得到了以下结果 -> https://jsfiddle.net/Taliesin84/qL35nejo/

我目前的目标是防止搜索栏在尺寸太小时环绕在折叠按钮下方。我还需要在更大的屏幕尺寸下使搜索栏更宽,但目前这是次要的。有什么新想法吗?

最佳答案

来自 Bootstrap 4 的 github 存储库中包含的示例:

<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>

关于html - Bootstrap 4 Alpha 6.搜索框在导航栏折叠时溢出容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46549677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com