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

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

效果展示

在这里插入图片描述

核心代码

<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>
相关文章
|
算法 搜索推荐 数据库
SEO免费流量难搞?试试360下拉词优化
SEO免费流量难搞?试试360下拉词优化
802 0
|
前端开发
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
172 0
弹性布局案例实操(京东网页对草稿页面进行改进)(二)
|
Web App开发 存储 安全
工具资源合集【置顶】
工具资源合集【置顶】
584 0
仿写一个登录页(布局篇)|青训营笔记
在使用 APP 派对岛 的时候,发现它的页面很好看,同时其首要的登录方法也是跳转去采用抖音来登录的。符合当前的业务需求,所以决定仿写该页面作为大作业的登录界面。
仿写一个登录页(布局篇)|青训营笔记
弹性布局案例实操(京东网页对草稿页面进行改进)(一)
弹性布局案例实操(京东网页对草稿页面进行改进)(一)
402 0
|
前端开发
整活系列(三)——做一个动态搜索框
动态的搜索框已经不是什么稀有的东西了,因为它的**动**,它可以出现在任何符合它位置的地方。
|
缓存 搜索推荐 UED
你的列表很卡?这4个优化能让你的列表丝般顺滑
本篇介绍了 Flutter 列表 ListView的4个优化要点,非常实用,让你的列表不再卡顿,丝般顺滑!
609 0
你的列表很卡?这4个优化能让你的列表丝般顺滑
|
前端开发 JavaScript
【前端】侧边栏收缩的优化
【前端】侧边栏收缩的优化
330 0
C++ 使得窗口置顶(终极方案)
C++ 使得窗口置顶(终极方案)
785 0