请做一个有动态效果的html搜索栏
时间: 2023-06-27 12:00:51 浏览: 45
好的,以下是一个简单的带有动态效果的 HTML 搜索栏:
```html
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Search Bar</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.search-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin-top: 50px;
}
.search-box {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
position: relative;
}
.search-box input[type="text"] {
width: 300px;
height: 40px;
padding: 10px;
border: none;
border-radius: 5px;
box-shadow: 0px 0px 5px rgba(0,0,0,0.2);
outline: none;
font-size: 16px;
background-color: #fff;
transition: width 0.3s ease-in-out;
}
.search-box input[type="text"]:focus {
width: 500px;
}
.search-box button {
position: absolute;
right: 0;
top: 0;
height: 40px;
width: 80px;
background-color: #4CAF50;
color: #fff;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
}
.search-box button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="search-container">
<div class="search-box">
<input type="text" placeholder="Search...">
<button type="submit">Search</button>
</div>
</div>
</body>
</html>
```
这个搜索栏在用户聚焦时会动态扩展宽度,以提供更多的空间来输入搜索内容。当用户输入搜索内容并点击“搜索”按钮时,可以触发搜索操作。