Hope you're having a wonderful day! ☺️
I recently created a responsive navigation menu bar for mobile devices, but it seems to be malfunctioning on some major browsers like Google Chrome and Bing. Instead of displaying the mobile view, it shows the desktop version.
If anyone has any ideas on how to fix this issue, I would greatly appreciate the help!
function toggleMenu() {
var menu = document.getElementById("menu");
menu.classList.toggle("open");
}
// Close the menu when a menu item is clicked (optional)
var menuItems = document.querySelectorAll(".menu li a");
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].addEventListener("click", function() {
var menu = document.getElementById("menu");
menu.classList.remove("open");
});
}
/* Responsive navigation styles */
nav {
background-color: #fff;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-weight: bold;
}
.menu {
display: flex;
list-style: none;
}
.menu li {
margin-right: 20px;
}
.menu li a {
text-decoration: none;
color: #333;
}
.menu-toggle {
cursor: pointer;
font-size: 20px;
}
/* Media queries */
@media only screen and (max-width: 768px) {
.menu {
display: none;
}
#menu.open {
display: flex;
flex-direction: column;
position: absolute;
top: 60px;
left: 0;
right: 0;
background-color: #fff;
padding: 20px;
}
#menu.open li {
margin-right: 0;
margin-bottom: 10px;
}
}
<header>
<nav>
<div class="logo">Maxin Solutions</div>
<div class="menu-toggle" onclick="toggleMenu()">☰</div>
<ul class="menu" id="menu">
<li><a href="/home">Home</a></li>
<li><a href="/about">About Us</a></li>
</ul>
</nav>
</header>
Any suggestions or tips on how to resolve this issue are welcome. I have tried adjusting the media screen pixel settings without success.