我正在使用bootstrap 3为角度4应用程序开发网页。
尝试添加搜索按钮(右上角/左上角),该按钮将在点击下一行中展开。 Refer top right corner search button here.
<div class="row">
<div class="col-xs-3">
<form id="demo-2" style="margin-left: 10px">
<input type="search" placeholder="Search..">
</form>
</div>
</div>
CSS
input {
outline: none;
}
input[type=search] {
-webkit-appearance: textfield;
-webkit-box-sizing: content-box;
font-family: inherit;
font-size: 100%;
}
input::-webkit-search-decoration,
input[type=search] {
background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 9px center;
border: solid 1px #ccc;
padding: 7px 9px 7px 17px;
width: 55px;
border-radius: 1em;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
input[type=search]:focus {
width: 170px;
background-color: #fff;
-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
box-shadow: 0 0 5px rgba(109,207,246,.5);
}
#demo-2 input[type=search] {
width: 15px;
padding-left: 10px;
color: transparent;
cursor: pointer;
}
#demo-2 input[type=search]:hover {
background-color: #fff;
}
#demo-2 input[type=search]:focus {
width: 200px;
padding-left: 32px;
color: #000;
background-color: #fff;
cursor: auto;
color: black;
}
#demo-2 input:-moz-placeholder {
color: transparent;
}
#demo-2 input::-webkit-input-placeholder {
color: transparent;
}
这使我的搜索栏在同一行中展开。我试图得到相同的例子。但所有人都谈论扩大同一行。
注意:搜索栏&amp;搜索按钮将位于桌面视图的同一行。 Similar to this。将根据移动视图进行更改。
提前致谢。建议是最受欢迎的。
答案 0 :(得分:0)
搜索按钮实际上并未在下一行展开,它会切换位于其下方的新元素。看看下面的例子,看看我的意思。
选项1(使用简单的JQuery代码)
$(document).ready(function(){
$(".toggle-search").click(function(){
$(".search-input").toggle();
});
});
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<button class="toggle-search"> Search </button>
<div class="container">
<form class="row search-input" id="demo-2" style="margin-left: 10px">
<input class="col-lg-12" type="search" placeholder="Search..">
</form>
</div>
选项2(不包含其他JQuery代码但仍需要JQuery库)
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-info" data-toggle="collapse" data-target=".search-input"> Search </button>
<div class="container collapse search-input">
<form class="row" id="demo-2" style="margin-left: 10px">
<input class="col-lg-12" type="search" placeholder="Search..">
</form>
</div>