Hi there, I’m totally new to this html stuff and I was trying to create a website by following a tutorial. I’m pretty sure I’ve followed every step exactly but cannot for the life of me get the dropdown menu to work. Could someone please look this over and guide me.
<!doctype html>
<html lang="en">
<head>
<title>My Website</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<nav>
<ul class="topnav" id="dropdownclick">
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
<li class="topnav-right"><a href="#signup">Sign Up</a></li>
<li class="topnav-right"><a href="#signin">Sign In</a></li>
<li class="dropdownicon"><a href= "" onclick="dropdownmenu()">☰</a></li>
</ul>
</nav>
<script>
function dropdownmenu() {
var x = document.getElementById("dropdownclick");
if (x.classname === "topnav") {
x.classname += " responsive";
/*change topnav to topnav.responsive*/
} else {
x.classname = "topnav";
}
}
</script>
</body>
</html>
/*##############Defaults##########*/
nav,
header,
footer {
display: block;
}
body {
line-height: 1;
margin: 0;
}
/*###########Nav Bar##########*/
nav {
width: 100%;
margin: 0;
}
nav ul {
background-color: #eee;
overflow: hidden;
margin: 0;
padding: 0;
}
ul.topnav li {
list-style: none;
float: left;
}
ul.topnav li.topnav-right {
float: right;
}
ul.topnav li a {
display: block;
text-decoration: none;
min-height: 16px;
text-align: center;
padding: 14px;
text-transform: uppercase;
color: #666;
}
ul.topnav li a:hover {
background-color: #0080ff;
color: white;
}
ul.topnav li.dropdownicon {
display: none;
}
/*##############mobile##########*/
@media screen and (max-width: 680px) {
ul.topnav li:not(:nth-child(1)){
display: none;
}
ul.topnav li.dropdownicon {
display: block;
float: right;
}
ul.topnav.responsive li.dropdownicon {
position: absolute;
top: 0;
right: 0;
}
ul.topnav.responsive {
position: relative;
}
ul.topnav.responsive li {
display: inline;
float: none;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
}