I am currently working on a project that involves toggling a class on a ul
tag with an id of sideNav
using JavaScript.
In this scenario, I have set the left
attribute of the id to 0
, while the same attribute in the class has a value of -100%
.
After several attempts to troubleshoot the issue, it seems that using the same property with different values is causing a problem. Are there any alternatives or solutions to overcome this challenge?
Here is a snippet of my code:
var btn = document.getElementById("burgerWrapper");
var sideNav = document.getElementById("sideNav");
btn.addEventListener("click", () => {
sideNav.classList.toggle("activeNav");
})
#sideNav {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
left: 0;
right: 0;
margin: 1rem 0;
}
.activeNav {
left: -100%;
}
<ul id="sideNav">
<li><a href="#">Option1</a></li>
<li><a href="#">Option2</a></li>
<li><a href="#">Option3</a></li>
</ul>