【前端练手小Demo】优雅实现伸缩搜索框
【摘要】 @TOC 效果展示 核心代码<style>.inputBox { width: 50px; height: 50px; position: relative; z-index: 999; /* 绝对定位,元素水平垂直居左 */ /* position: absolute; top: 10%; left: 20%; */}.inputBox .search { p...
@TOC
效果展示
核心代码
<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>
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)