首页 > 其他分享 >【每日一练】18—搜索框效果的实现

【每日一练】18—搜索框效果的实现

时间:2022-11-07 17:08:28浏览次数:49  
标签:search 18 每日 height content width 搜索 background position

【每日一练】18—搜索框效果的实现_ico


写在前面

搜索框是很常用的一个功能,因此,今天我们一起来练习写一个搜索框的效果,希望今天的这个练习对你有帮助,下面我们一起来看今天练习的最终效果:

【每日一练】18—搜索框效果的实现_搜索_02

HTML代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>【每日一练】18—搜索框效果的实现</title>
</head>
<body>
<div class="search">
<div class="icon"></div>
<div class="input">
<input type="text" name="" id="SearchInput" placeholder="Search">
</div>
<span class="clear" onclick="document.getElementById('SearchInput').value = ''"></span>
</div>
<script type="text/javascript">
const icon = document.querySelector('.icon');
const search = document.querySelector('.search');
icon.onclick = function(){
search.classList.toggle('active');
}
</script>
</body>
</html>

CSS代码:

*
{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body
{
position: relative;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #fafafa;
}
.search
{
position: relative;
width: 60px;
height: 60px;
background: #fff;
border-radius: 60px;
overflow: hidden;
transition: 0.5s;
box-shadow: 0 0 0 2px #00a6bc;
}
.search.active
{
width: 360px;
}
.search .icon
{
position: absolute;
left: 0;
top: 0;
width: 60px;
height: 60px;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
z-index: 1;
}
.search .icon:before
{
content: '';
position: absolute;
width: 15px;
height: 15px;
border: 3px solid #00a6bc;
border-radius: 50%;
transform: translate(-4px,-4px);
transition: 0.5s;
}


.search .icon:after
{
content: '';
position: absolute;
width: 3px;
height: 12px;
background:#00a6bc;
transform: translate(6px,6px) rotate(315deg);
}


.search .input
{
position: relative;
width: 300px;
height: 60px;
left: 60px;
background: #f0f;
display: flex;
justify-content: center;
align-items: center;
}
.search .input input
{
position: absolute;
top: 0;
width: 100%;
height: 100%;
padding: 10px 0;
border: none;
outline: none;
font-size: 18px;
}


.clear
{
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 15px;
width: 15px;
height: 15px;
display: block;
background: #fff;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.clear:before
{
position: absolute;
content: '';
width: 1px;
height: 15px;
background: #999;
transform: rotate(45deg);
}
.clear:after
{
position: absolute;
content: '';
width: 1px;
height: 15px;
background: #999;
transform: rotate(315deg);
}

写在最后

以上就是每日一练的全部内容,希望今天的小练习对你有用,如果你觉得有帮助的话,请点赞我,关注我,并将它分享给你身边做开发的朋友,也许能够帮助到他。

我是杨小爱,我们明天见。

【每日一练】18—搜索框效果的实现_html_03

【每日一练】18—搜索框效果的实现_html_04


标签:search,18,每日,height,content,width,搜索,background,position
From: https://blog.51cto.com/u_15809510/5830060

相关文章

  • 【每日一练】19—CSS 实现撕纸的效果
    写在前面今天我们来练习一个CSS实现的撕纸效果,这个效果,也会在一些设计网站上经常看到,但是这个用PS可以直接做成一张图片,但是,今天我们用CSS通过两张图片就实现了,这样做的好处......
  • 【每日一练】20—CSS实现文字动画效果
    写在前面今天来到了我们的第20个小项目的练习,距离我们100个小项目的练习,我们已经完成了五分之一了,剩下的五分之四,我们一起加油练习。今天练习的这个小项目是一个CSS实现的文......
  • 【每日一练】21—CSS实现炫酷动画背景
    今天分享的这个小练习,我们在视频号上分享过,具体效果请看下面的视频:因为在视频号的后台,有小伙伴留言说,想要这个案例的源码,所以,今天就把这个源码也分享出来了,有兴趣的小伙伴可......
  • nginx1.18配置https,tomcat9也配置https
    生成证书:https://www.cnblogs.com/caidingyu/p/11904277.htmltomcat9https://blog.csdn.net/lzj_lives/article/details/123824964server.xml<Connectorport="90......
  • 538.把二叉搜索树转换为累加树
    给出二叉 搜索 树的根节点,该树的节点值各不相同,请你将其转换为累加树(GreaterSumTree),使每个节点 node 的新值等于原树中大于或等于 node.val 的值之和。提醒一下,二......
  • E710八通道读写器7189 Lite
    简介   E710八通道超高频电子标签读写器是一款高性能的UHF超高频电子标签读写器,完全自主知识产权设计,结合专有的高效信号处理算法,在保持高识读率的同时,实现对电子标签的......
  • 2022-11-07 Acwing每日一题
    本系列所有题目均为Acwing课的内容,发表博客既是为了学习总结,加深自己的印象,同时也是为了以后回过头来看时,不会感叹虚度光阴罢了,因此如果出现错误,欢迎大家能够指出错误,我......
  • ES拼音搜索分词器练习
    #拼音分词器GET_analyze{"text":"如家酒店","analyzer":"pinyin"}#ik分词器GET_analyze{"text":"如家酒店","analyzer":"ik_smart"}DELETEtestPUT/test......
  • Elasticsearch拼音搜索:自定义分词器的模板
    PUT/test{"settings":{"analysis":{"analyzer":{"my_analyzer":{"tokenizer":"ik_max_word","filter":"py"}......
  • 数据结构 玩转数据结构 6-7 二分搜索树的中序遍历和后续遍历
    0课程地址https://coding.imooc.com/lesson/207.html#mid=13460 1重点关注1.1什么是中序遍历和后续遍历中序遍历:就是先遍历左节点,再遍历根......