I have a ul
tag with an id of sideNav
and I'm toggling a class on it with JavaScript.
For the id styles, I have a left
attribute with the value of 0
, while on the class I have the same attribute with a value of -100%
.
I have tried a lot of things to discover what the problem is and I've come to the conclusion that I can't use the same property with a different value in this case.
Why? Do you know any alternatives? Am I missing something here?
This is 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>