html导航栏+搜索栏+二级菜单
时间: 2023-07-25 19:47:18 浏览: 87
好的,下面是一个简单的HTML导航栏、搜索栏和二级菜单的示例代码:
```
<!DOCTYPE html>
<html>
<head>
<title>导航栏示例</title>
<style>
/* 导航栏样式 */
nav {
background-color: #333;
overflow: hidden;
font-size: 16px;
}
nav a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
nav a:hover {
background-color: #ddd;
color: black;
}
/* 搜索栏样式 */
.search-container {
float: right;
}
input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: none;
}
button {
float: right;
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: none;
cursor: pointer;
}
button:hover {
background: #ccc;
}
/* 二级菜单样式 */
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: #ddd;
color: black;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<!-- 导航栏 -->
<nav>
<a href="#">首页</a>
<a href="#">新闻</a>
<div class="dropdown">
<button class="dropbtn">菜单1</button>
<div class="dropdown-content">
<a href="#">选项1</a>
<a href="#">选项2</a>
<a href="#">选项3</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">菜单2</button>
<div class="dropdown-content">
<a href="#">选项1</a>
<a href="#">选项2</a>
<a href="#">选项3</a>
</div>
</div>
<div class="search-container">
<form action="">
<input type="text" placeholder="搜索...">
<button type="submit">搜索</button>
</form>
</div>
</nav>
<!-- 页面内容 -->
<div>
<h1>欢迎来到我的网站</h1>
<p>这是一个示例页面,用于演示导航栏、搜索栏和二级菜单的实现。</p>
</div>
</body>
</html>
```
你可以将上面的代码复制到一个 HTML 文件中,然后用浏览器打开它,即可看到效果。当然,你可以根据自己的需要修改样式和内容。
阅读全文