动态搜索框
代码如下
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>你好,小周</title>
<link rel="stylesheet" href="style6.css">
</head>
<body>
<div id="search-box">
<input class="search-txt" type="text" placeholder="搜索" >
<a class="search-btn">
<svg t="1612010397908" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2738" width="64" height="64"><path d="M192 448c0-141.152 114.848-256 256-256s256 114.848 256 256-114.848 256-256 256-256-114.848-256-256z m710.624 409.376l-206.88-206.88A318.784 318.784 0 0 0 768 448c0-176.736-143.264-320-320-320S128 271.264 128 448s143.264 320 320 320a318.784 318.784 0 0 0 202.496-72.256l206.88 206.88 45.248-45.248z" fill="#181818" p-id="2739"></path></svg>
</a>
</div>
</body>
</html>
CSS
body{
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family:"monospace";
background-image: linear-gradient(125deg,#2ecc71,#3498db,#8e44ad,#34495e);
background-size: 400%;
animation: change 15s infinite;
}
#search-box{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background: #424242;
height: 40px;
border-radius: 40px;
padding: 10px;
}
.search-btn{
color: #e84118;
float: right;
width: 40px;
height: 40px;
border-radius: 50%;
background: #424242;
display: flex;
justify-content: center;
align-items: center;
transition: 0.4s;
}
.search-txt{
border: none;
background: none;
outline: none;
float: left;
padding: 0;
color: white;
font-size: 16px;
transition: 0.4s;
line-height: 40px;
width: 0;
}
#search-box:hover>.search-txt{
width: 200px;
padding: 0 6px;
}
#search-box:hover>.search-btn{
background: white;
}
@keyframes change{
0%{
background-position: 0% 50%;
}
50%{
background-position: 100% 50%;
}
100%{
background-position: 0% 50%;
}
}
效果展示
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bb6cb77a66949075c6ebf753612f41b0.gif#pic_center)