I learning from frontend mentor,
my problem is when my screen < 1000px, I click at icon-hamburger then I expand screen > 1000px,why property unchanged?, how can I fix this problem?
i cant add all code because it limited from stackoverflow. thank for helping
index.html
<header>
<nav>
<img class="logo" src="./assets/images/logo.svg" alt="">
<div class="menu">
<a href="">Home</a>
<a href="">New</a>
<a href="">Popular</a>
<a href="">Trending</a>
<a href="">Categories</a>
</div>
<div class="icon">
<img id = "icon-close" src="./assets/images/icon-menu-close.svg" alt="">
<img id ="icon-hamburger" src="./assets/images/icon-menu.svg" alt="">
</div>
</nav>
</header>
styles.css
:root{
--mainwidth: 80%;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
a{
text-decoration: none;
}
header{
border: solid pink 1px;
}
nav{
display: flex;
align-items: center;
justify-content: space-between;
border: solid green 1px;
max-width: var(--mainwidth);
margin: 0 auto;
padding: 10px 0;
}
#icon-close, #icon-hamburger{
position: relative;
width: 20px;
z-index: 9999;
cursor: pointer;
}
#icon-close{
display: none;
}
nav .menu{
/* border: solid red 1px; */
/* display: flex when Desktop size*/
display: none;
align-items: center;
gap: 5px;
}
.show-drop-menu{
background: white;
top: 0;
bottom: 0;
right: 0;
width: 65vw;
padding-top: 10vh;
flex-direction: column;
position: fixed;
}
@media only screen and (min-width: 1000px){
#icon-hamburger,#icon-close,.icon{
border: solid yellow 1px;
display: none;
}
nav .menu{
display: flex;
}
.show-drop-menu{
display: none;
}
}
scripts.js
const icon_hamburger = document.querySelector("#icon-hamburger");
const icon_close = document.querySelector("#icon-close");
const menu = document.querySelector(".menu");
icon_hamburger.addEventListener("click", () => {
icon_hamburger.style.display = 'none';
icon_close.style.display = 'flex';
menu.style.display = 'flex';
menu.classList.add("show-drop-menu");
});
icon_close.addEventListener("click", () => {
icon_close.style.display = 'none';
icon_hamburger.style.display = 'flex';
menu.style.display = 'none';
menu.classList.remove("show-drop-menu");
});
enter image description here