Good Afternoon,
This is my first project and im attempting to make my nav bar responsive. when re adjusting the size I am having issues with the toggle button working as expected. I expect it to provide a list of drop downs when click on it however nothing happens when I click on the button.
please see code snippets below and thanks in advance : )
<nav class="navbar">
<div class="itpslogo"><img src="img/ITPS.png" alt=""></div>
<a href="#" class="toggle-button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div class="navbar-links">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</nav>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #00BFFF;
}
.itpslogo {
width: 100%;
height: auto;
margin: 0.5rem;
}
.navbar-links ul {
margin: 0;
padding: 0%;
display: flex;
}
.navbar-links li {
list-style: none;
}
.navbar-links li a {
text-decoration: none;
color: white;
padding: 3rem;
display: block;
font-size: large;
}
.toggle-button {
position: absolute;
top: 0.75rem;
right: 1rem;
display: none;
flex-direction: column;
justify-content: space-between;
width: 30px;
height: 21px;
}
.toggle-button .bar {
height: 3px;
width: 100%;
background-color: white;
border-radius: 3px;
}
@media (max-width: 800px) {
.navbar {
flex-direction: column;
align-items: flex-start;
}
.toggle-button {
display: flex;
}
.navbar-links {
display: none;
width: 100%;
}
.navbar-links ul {
width: 100%;
flex-direction: column;
}
.navbar-links ul li {
text-align: center;
}
.navbar-links ul li a {
padding: .5rem 1rem;
}
.navbar-links.active {
display: flex;
}
}
const toggleButton = document.getElementsByClassName('toggle-button')[0]
const navbarLinks = document.getElementsByClassName('navbar-links')[0]
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active')
})