I want to create a responsive navigation bar that the responsive when opened on a phone. I am trying to implement a Burger Menu. I have added the code for a burger menu in my html, css and js code but its not working.
Here is my part of the code relating to the navigation bar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home </title>
<link rel="stylesheet" href="style.css">
<link rel="icon" href="Favicon/favicon.ico"/>
</head>
<body>
<header>
<h1>Tallinn University HCI Hub</h1>
<p>Connecting the World of Human-Computer Interaction</p>
</header>
<div class="navbar">
<div class="burger-menu" onclick="toggleMenu()">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
<nav class="nav-links">
<nav>
<ul>
<li><a href="events.html">Events</a></li>
<li><a href="speakers.html">Speakers</a></li>
<li><a href="testimonials.html">Testimonials</a></li>
<li><a href="meme.html">UniMeme Mingles</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="shop.html">UniStyle Event Shop</a></li>
</ul>
</nav>
.burger-menu {
display: none;
flex-direction: column;
cursor: pointer;
}
.bar {
width: 25px;
height: 3px;
background-color: white;
margin: 5px 0;
}
.burger-menu {
display: flex;
}
@media only screen and (max-width: 768px) {
.nav-links {
display: none;
flex-direction: column;
position: absolute;
top: 60px;
left: 0;
right: 0;
background-color: #333;
z-index: 1;
}
nav {
background-color: #34495e;
color: #ecf0f1;
padding: 0.5em;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-around;
}
nav a {
text-decoration: none;
color: #ecf0f1;
}
//index page
toggleMenu() {
var navLinks = document.querySelector('.nav-links');
navLinks.style.display = (navLinks.style.display === 'flex') ? 'none' : 'flex';
}`
I tried to use the burger menu so that my naviagtion bar is more responsive. But my code for the burger menu seems not to be working. How can i fix this and have the burger menu function or work well.