html css实现 好看的 搜索功能 及 搜索列表 代码
时间: 2023-05-29 20:03:27 浏览: 86
以下是一个简单的HTML和CSS代码,实现了一个简单的搜索功能和搜索列表。你可以根据需要进行修改和定制。
HTML代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>搜索功能</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="search-box">
<input type="text" placeholder="输入关键字">
<button type="submit">搜索</button>
</div>
<ul class="search-list">
<li><a href="#">搜索结果1</a></li>
<li><a href="#">搜索结果2</a></li>
<li><a href="#">搜索结果3</a></li>
<li><a href="#">搜索结果4</a></li>
<li><a href="#">搜索结果5</a></li>
</ul>
</body>
</html>
```
CSS代码:
```
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.search-box {
display: flex;
justify-content: center;
margin-top: 50px;
}
.search-box input[type="text"] {
width: 300px;
padding: 10px;
border: none;
border-radius: 5px 0 0 5px;
font-size: 16px;
}
.search-box button[type="submit"] {
padding: 10px 20px;
background-color: #2196F3;
border: none;
border-radius: 0 5px 5px 0;
color: white;
font-size: 16px;
cursor: pointer;
}
.search-list {
margin-top: 30px;
list-style: none;
padding: 0;
text-align: center;
}
.search-list li {
margin-bottom: 10px;
}
.search-list a {
display: inline-block;
padding: 10px 20px;
background-color: white;
border: 1px solid #ccc;
border-radius: 5px;
color: #333;
font-size: 16px;
text-decoration: none;
transition: all 0.3s ease;
}
.search-list a:hover {
background-color: #2196F3;
color: white;
border-color: #2196F3;
}
```
在这个代码中,我们首先创建了一个搜索框和一个搜索按钮,以及一个搜索列表。搜索框和搜索按钮被包装在一个div中,搜索列表被包装在一个ul中。我们使用CSS来对这些元素进行样式设置,从而实现一个简单的搜索功能和搜索列表。