这样实现伸缩搜索框实在优雅

简介: 本博文主要介绍:如何实现搜索框

效果展示

在这里插入图片描述

核心代码

<style>
.inputBox {
  width: 50px;
  height: 50px;
  position: relative; 
  z-index: 999;
  /* 绝对定位,元素水平垂直居左 */
  /*  position: absolute;
    top: 10%;
    left: 20%; */
}
.inputBox .search {
  position: absolute;
  margin: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 50px;
  height: 50px;
  background: #517bd6;
  border-radius: 50%;
  transition: all 1s;
  z-index: 4;
  box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.1);
}
.inputBox .search:hover {
  cursor: pointer;
}
.inputBox .search::before {
  content: "";
  position: absolute;
  margin: auto;
  top: 18px;
  right: 0;
  bottom: 0;
  left: 18px;
  width: 10px;
  height: 2px;
  background: white;
  transform: rotate(45deg);
  transition: all .5s;
}
.inputBox .search::after {
  content: "";
  position: absolute;
  margin: auto;
  top: -3px;
  right: 0;
  bottom: 0;
  left: -3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid white;
  transition: all .5s;
}
.inputBox input {
  position: absolute;
  margin: auto;
  top: 0;
  right: 0;
  bottom: 0;
  /* left: 0; */
  width: 40px;
  height: 40px;
  outline: none;
  border: none;
  background: #fff;
  color: #777;
  border-radius: 30px;
  box-shadow: 0 0 25px 0 #517bd6, 0 0px 15px 0 rgba(0, 0, 0, 0.5);
  transition: all 1s;
  opacity: 0;
  z-index: 5;
  font-weight: bolder;
}
.inputBox input:hover {
  cursor: pointer;
}
.inputBox input:focus {
  width: 300px;
  padding: 0 80px 0 20px;
  opacity: 1;
  cursor: text;
}
.inputBox input:focus ~ .search {
  right: 0px;
  background: #f60;
  z-index: 6;
}
.inputBox input:focus ~ .search::before {
  top: 0;
  left: 0;
  width: 25px;
}
.inputBox input:focus ~ .search::after {
  top: 0;
  left: 0;
  width: 25px;
  height: 2px;
  border: none;
  background: white;
  border-radius: 0%;
  transform: rotate(-45deg);
}
.inputBox input::placeholder {
  color: #777;
  opacity: 0.8;
}
</style>

<div class="inputBox">
    <input type="text" placeholder="查询房屋 如输入太原">
    <div class="search"></div>
</div>
相关文章
|
17天前
Dokcer搭建一个极致简约的导航页
Dokcer搭建一个极致简约的导航页
10 0
|
7月前
|
算法 搜索推荐 数据库
SEO免费流量难搞?试试360下拉词优化
SEO免费流量难搞?试试360下拉词优化
|
9月前
|
JavaScript 程序员 API
轻量好看的笔记工具,虽然小但操作真的骚|flomo
轻量好看的笔记工具,虽然小但操作真的骚|flomo
|
9月前
|
存储 XML JSON
简简单单搞一个实用的Android端搜索框
效果很常见,就是平常需求中的效果,上面是搜索框,下面是最近和热门搜索列表,为了方便大家在实际需求中使用,配置了很多属性,也进行了上下控件的拆分,也就是上边搜索框和下面的搜索列表的拆分,可以按需进行使用。
109 0
|
前端开发
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
123 0
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
弹性布局案例实操(京东网页对草稿页面进行改进)(一)
弹性布局案例实操(京东网页对草稿页面进行改进)(一)
341 0
|
缓存 自然语言处理 安全
CleanMyMac X2023好不好用?功能详情解读
CleanMyMac X之所以能够获得众多Mac老用户们的喜爱,是因为其有着非常强大功能提升Mac的使用性能,如智能清理磁盘空间、快速体检杀毒、保护安全隐私和提升Mac运行速度等等。今天小编就针对大家常遇到Mac运行速度越来越卡顿的问题,教教大家如何使用CleanMyMac X提升Mac的运行速度,非常管用。CleanMyMac X2023下载如下:http://t.csdn.cn/sa393
108 0
|
前端开发
整活系列(三)——做一个动态搜索框
动态的搜索框已经不是什么稀有的东西了,因为它的**动**,它可以出现在任何符合它位置的地方。
|
缓存 搜索推荐 UED
你的列表很卡?这4个优化能让你的列表丝般顺滑
本篇介绍了 Flutter 列表 ListView的4个优化要点,非常实用,让你的列表不再卡顿,丝般顺滑!
361 0
你的列表很卡?这4个优化能让你的列表丝般顺滑