So I'm trying to make a navbar and make the mobile version of it following a tutorial but the burger drop down is not working .I spent hours trying to figure this out but I cant find what's wrong
const navSlide = () => {
const burger = document.querySelector(".burger");
const nav = document.querySelector(".nav-links");
burger.addEventListener("click", function() {
nav.classList.toggle('nav-active');
});
}
navSlide();
* {
margin: 0;
padding: 0;
box-sizing: border-box;
text-decoration: none;
}
.nav {
display: flex;
align-items: center;
justify-content: space-around;
font-family: 'Poppins', sans-serif;
background-color: #5d4954;
min-height: 8vh;
}
.logo {
color: rgb(196, 194, 194);
text-transform: uppercase;
letter-spacing: 5px;
font-size: 20px;
font-weight: bold;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 50%;
padding-right: 0px;
font-weight: bold;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: rgb(196, 194, 194);
text-decoration: none;
letter-spacing: 2px;
font-weight: bold;
font-size: 14px;
}
.burger div {
background-color: rgb(196, 194, 194);
margin: 5px;
width: 25px;
height: 3px;
}
.burger {
display: none;
cursor: pointer;
}
@media screen and (max-width:768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #5d4954;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%);
}
/*
@media screen and(max-width:1024px){
.nav-links{
width: 60%;
}
}*/
<html lang="en">
<head>
<script src="app.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>navbar</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200&display=swap" rel="stylesheet">
</head>
<body>
<nav class="nav">
<div class="logo">
<p>my nav</p>
</div>
<ul class="nav-links">
<li class="el"><a href="#">Home</a></li>
<li class="el"><a href="#">About</a></li>
<li class="el"><a href="#">work</a></li>
<li class="el"><a href="#">projects</a></li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
</body>
</html>
the JavaScript looks fine cause I traced it word for word, but its the CSS I'm kind of worried about maybe there is a problem in the media queries I made. thanks in advance :)
i realized that it runs well here when you click run snippet but it doesn't in chrome using live server in vscode, what is the problem???