gpt4 book ai didi

html - 如何在中间使用全尺寸搜索表单制作 bootstrap 3 响应式导航栏?

转载 作者:行者123 更新时间:2023-11-28 01:42:07 24 4
gpt4 key购买 nike

我正在尝试创建一个包含搜索表单的导航栏,该表单将填充 .navbar-brand.navbar-collapse 内容之间的所有剩余空间.

当视口(viewport)的宽度小于 767 像素时(当导航栏的折叠样式被触发时),我的代码工作正常。但是当视口(viewport)的宽度超过 767px 时,搜索表单变小了..

这是 html:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="sr-only"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-search_container">
<div class="full_width_div">
<div class="right_part-wrapper">
<a class="btn btn-default">z</a>
</div>
<div class="remaining-wrapper">
<form class="my-search_form-group">
<div class="input-group">
<input type="text" class="form-control" name="q" placeholder="keyword">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
a
</button>
</span>
</div>
</form> <!-- /.my-search_form-group -->
</div> <!-- /.left_part-wrapper -->
</div> <!-- /.full_width_div -->
</div> <!-- /.navbar-search_container -->
</div> <!-- /.navbar-header -->
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>

<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>

</body>
</html>

这是CSS:

/* css to allow a div fit remaining width
based on https://stackoverflow.com/a/5043876/1235167 */
.full_width_div {
width: 100% !important;
}
.full_width_div > .right_part-wrapper {
/* white-space: nowrap; */
float: right;
}
.full_width_div > .left_part-wrapper {
float: left;
}
.full_width_div > .remaining-wrapper {
/* white-space: nowrap; */
overflow: hidden;
}

这是 jsfiddle

在修改了开发者工具后,我发现我的代码只适用于小于 767 像素的视口(viewport),因为 .navbar-header 在低于 767 像素时会获得“width:100%”规则。所以现在我想我需要制作 .navbar-search_container 部分来填充 .navbar-collapse 的内容留下的剩余空间。我怎么做?它们在不同的 DOM 级别和结构上。请帮忙。我已经为此工作了好几天..

最佳答案

设置最小宽度结合媒体查询可能是一个选项:

@media (min-width: 768px) {
.full_width_div {
min-width: 500px;
}
}

fiddle

关于html - 如何在中间使用全尺寸搜索表单制作 bootstrap 3 响应式导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50385741/

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