搜索按钮下方的搜索栏 - 点击

问题描述 投票:0回答:1

我正在使用 bootstrap 3 为 Angular 4 应用程序开发网页。

尝试添加一个搜索按钮(右上角/左上角),单击该按钮将在下一行展开。 在这里参考右上角的搜索按钮。

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

这让我在同一行中展开搜索栏。我试图获得相同的例子。但是他们都在谈论扩大同一行。

注意:对于桌面视图,搜索栏和搜索按钮将位于同一行。 类似这个。将根据移动视图做出响应。

提前致谢。欢迎提出建议。

html css twitter-bootstrap twitter-bootstrap-3 responsive-design
1个回答
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>

© www.soinside.com 2019 - 2024. All rights reserved.