gpt4 book ai didi

html - 在始终显示的 Bootstrap 导航栏中创建全宽搜索输入

转载 作者:太空宇宙 更新时间:2023-11-04 02:54:22 25 4
gpt4 key购买 nike

目标

我正在尝试创建一个 Bootstrap 导航栏,其中包括始终显示的全宽搜索输入(当导航栏折叠和未折叠时)以及紧邻搜索右侧的下拉列表,该列表像往常一样切换.

未折叠

enter image description here

折叠

enter image description here

我的解决方案

我能够通过在导航栏 header 内定义搜索输入并应用一些 css 使其全宽来实现这一点。但是,为了使选项下拉列表正确显示折叠未折叠 View 中保持搜索输入的全宽,我应用了我只能描述为一系列黑客的东西。我想帮助想出一个合适的解决方案。

第一次黑客攻击

我在标题中定义了选项。当我在标题外定义选项时,我要么无法让搜索保持完整宽度,要么无法将搜索和选项保持在同一行,具体取决于我尝试的不同解决方案。

第二个黑客

为了使选项显示在相对于搜索的正确位置(未折叠时在右侧,折叠时在下方),我必须复制(我知道这很糟糕)选项 div .我在搜索输入之前定义了一个,在搜索输入之后定义了一个。然后,我应用 css hack,根据导航栏是否折叠,仅显示两个选项之一。

问题

我创建了一个精简的 bootply这显示了我的工作技巧。我怎样才能以正确的方式完成这项工作?我很乐意完全放弃我的方法,转而采用更清洁的解决方案。

免责声明:我对 HTML/CSS 和 Bootstrap 还是很陌生,所以我可能以错误的方式做各种事情。

相关的 HTML

    <nav class="navbar navbar-default navbar-fixed-top" ng-controller="SearchController">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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 class="collapse navbar-collapse navbar-right navbar-hack1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Options<span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Some Options</li>
<li>
<select><option>Option 1</option><option>Option 2</option></select>
</li>
</ul>
</li>
</ul>
</div>
<div class="search form-inline">
<input type="text" class="form-control input-lg" role="search" id="query" placeholder="Search">
</div>
<div class="collapse navbar-collapse navbar-right navbar-hack2" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Options<span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Some Options</li>
<li>
<select><option>Option 1</option><option>Option 2</option></select>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</nav>

相关CSS

.navbar-header {
float: none !important;
}

@media (min-width: 768px) {
.navbar-header {
float: none !important;
}

.navbar-collapse {
float: right !important;
}

.navbar-hack2.collapse {
display: none !important;
}

.search {
margin-right: 100px !important;
}

.search input {
width: 100% !important;
}
}

@media (max-width: 767px) {
.navbar-hack1 {
display: none !important;
}
}

最佳答案

这可能会对您有所帮助或给您一些想法。

/**Custom**/

body,
html {
margin-top: 60px;
}
.navbar-default .formSearch {
left: 0;
position: absolute;
width: 85%;
}
.navbar-default #search-input {
height: 50px;
background: #f5f5f5;
color: #444;
box-shadow: none;
outline: none;
font-size: 20px;
border: none;
}
@media (max-width: 360px) {
.navbar-default #search-input {
width: 85%;
font-size: 16px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
<form class="formSearch" role="search">
<input type="text" class="form-control" id="search-input" placeholder="Search for Something...">
</form>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>

<ul class="dropdown-menu">
<li><a href="#">Action</a>

</li>
<li><a href="#">Another action</a>

</li>
<li><a href="#">Something else here</a>

</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>

</li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a>

</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="container">
<div class="well well-lg">
<h1>Boostrap Search Bar</h1>

</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since
the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.</p>
</div>

关于html - 在始终显示的 Bootstrap 导航栏中创建全宽搜索输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32440244/

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