html+css動態搜尋框
阿新 • • 發佈:2021-02-15
動態搜尋框
程式碼如下
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%;
}
}