用HTML写一个搜索栏和导航栏
时间: 2023-10-31 13:06:18 浏览: 42
好的,下面是一个简单的 HTML 示例,包含搜索栏和导航栏:
```html
<!DOCTYPE html>
<html>
<head>
<title>搜索栏和导航栏示例</title>
<style>
/* 导航栏样式 */
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
/* 搜索栏样式 */
#search-bar {
display: inline-block;
margin-top: 10px;
margin-right: 10px;
}
#search-bar input[type="text"] {
padding: 8px;
border: none;
border-radius: 4px;
font-size: 16px;
outline: none;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
#search-bar button {
background-color: #4CAF50;
color: white;
padding: 8px;
border: none;
border-radius: 4px;
cursor: pointer;
}
#search-bar button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<!-- 导航栏 -->
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">新闻</a></li>
<li><a href="#">体育</a></li>
<li><a href="#">科技</a></li>
<li><a href="#">娱乐</a></li>
</ul>
<!-- 搜索栏 -->
<div id="search-bar">
<form>
<input type="text" placeholder="搜索...">
<button type="submit">搜索</button>
</form>
</div>
</body>
</html>
```
你可以将这个 HTML 代码复制到一个新建的文件中,然后在浏览器中打开该文件,就可以看到一个包含搜索栏和导航栏的网页了。