When the menu appears on the right side with right: 0;
, I change it to right: -200px
; when closing it so that the mobile page does not show the menu on the right. My goal is to display the fa-bars
symbol when the menu is closed (right: -200px;
), and the fa-xmark
element when the menu is open (right: 0px;
). Despite trying various code variations, I have been unable to achieve this.
@media (max-width: 700px) {
.nav_links ul li {
display: block;
}
nav .fa-bars {
display: block;
color: black;
margin: 10px;
font-size: 22px;
cursor: pointer;
position: absolute;
}
.nav_links {
position: absolute;
background: lightpink;
height: 100vh;
width: 200px;
top: 0;
right: 0px;
text-align: left;
z-index: 2;
}
nav .fa-xmark {
display: block;
color: black;
margin: 10px;
font-size: 22px;
cursor: pointer;
}
}
<nav class="nav_links">
<i class="fa-solid fa-xmark"></i>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Page</a></li>
<a class="button1" href="#"><button>My Instagram</button></a>
</ul>
<i class="fa-solid fa-bars"></i>
</nav>