html - 带有下拉菜单的响应式导航栏不显示下拉菜单
问题描述
我必须放置一个带有子菜单的响应式菜单。我找到了这一课:https ://www.w3schools.com/howto/howto_js_responsive_navbar_dropdown.asp
菜单本身出来了,但是当我单击“下拉”按钮时,根本不显示子菜单。我试图更改一些代码,但什么也没有。
我该如何解决这个问题或在哪里寻找问题?
提前致谢!
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
#navbaronder {
background-color: #dddddd;
margin: 155px 0px 0px 0px; /* viso4ina na drop down menuto*/
transition: 0.4s;
position: fixed;
width: 100%;
top: 0;
z-index: 500;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<style>
body {margin:0;font-family:Arial}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: right;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.active {
background-color: #4CAF50;
color: white;
}
.topnav .icon {
display: none;
}
.dropdown {
float: right;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
</style>
<div id="navbaronder">
<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="#about">About</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
</div>
解决方案
推荐阅读
- c - C语言~数据文件使用delete函数修改文本文件内容(File IO)
- python - 矩阵向量运算的 Python 向量化
- r - 根据条件使用 Dply 进行变异
- java - 从 android Studio 上的实时数据库中检索数据
- mysql - 无法在具有节点 v11.2.0 的 Ubuntu 18.04 中运行 PopSQL
- docker - NGINX问题无法访问root
- xamarin.ios - Xamarin.iOS 无法解析参考:System.Threading.Tasks.Extensions.dll
- amazon-web-services - AWS 支持或 AWS 专家
- spring-restdocs - 如何在 Spring Rest Docs 生成的 HTML 文档中包含应用程序版本号?
- mysql - 计算已经过去了多少个工作日