【发布时间】:2018-01-11 09:54:13
【问题描述】:
我在这里有点初学者,在 FreeCodeCamp 上做练习。在从事 Portfolio Site 项目时,我尝试通过 ws3schools 的一些代码向网站添加一个 Javascript 响应式移动导航。
导航显示正常,但单击它没有任何反应。这是我的 CodePen,我做了什么阻止它在点击时弹出导航链接? https://codepen.io/colum1225/pen/xLwMJG
这是导航条码:
<!-- HTML -->
<div class="topnav" id="myTopnav">
<h3>Brandon Ray</h3>
<a href="#contact">Contact</a>
<a href="#about">About</a>
<a href="#portfolio">Portfolio</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">☰</a>
</div>
<!-- CSS -->
.topnav {
background-color: #2C8597;
overflow: hidden;
width: 100%;
position: fixed;
z-index: 9;
}
.topnav h3 {
float: left;
color: #f2f2f2;
font-family: sans-serif;
font-size: 1.5em;
padding-left: 30px;
letter-spacing: .04em;
font-weight: 500;
}
.topnav a {
float: right;
display: block;
color: #f2f2f2;
text-align: center;
padding: 27px 30px 27px 30px;
text-decoration: none;
font-size: 1.25em;
font-family: sans-serif;
}
.topnav a:hover {
background-color: #ddd;
color: black;
transition: .5s;
}
.topnav a:active {
background-color: #ddd;
color: black;
}
.topnav .icon {
display: none;
font-size: 1.3em;
}
@media screen and (max-width: 640px) {
.topnav a {display: none;}
.topnav .icon {
float: right;
display: block;
color: white;
margin-right: 30px;
}
}
@media screen and (max-width: 640px) {
topnav.responsive {position: relative;}
topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
topnav.responsive a {
float: none;
display: block;
text-align: right;
}
}
<!-- JS -->
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
【问题讨论】:
标签: javascript css responsive nav