'Navbar links are visible but not clickable
I have created a mobile and tablet version for my navbar(which gets activated when you click on the hamburger) and on the desktop resolution, I want the navbar to be visible immediately. And I have done so far... but the navbar links are not clickable on the desktop version. The reason for that is because on the HTML part I added onClick action on the hamburger for the menu but on the desktop resolution I just make display: none for the hamburger menu so the user never actually activates the hamburger for the navbar links to become clickable.
So this is the HTML code:
<ul id="menu">
<li class="menu-item"><a href="/index.html" class="active">Home Page</a></li>
<li class="menu-item"><a href="/content.html" class="nav-link">Content</a></li>
<li class="menu-item"><a href="/store.html" class="nav-link">Products</a></li>
<li class="menu-item"><a href="/contact.html" class="nav-link">Contact</a></li>
</ul>
<input type="checkbox" id="check">
<div class="hamburger" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
This is the CSS code:
#check {
display: none;
}
#menu{
background-color: white;
margin: 60px 0 0 0;
padding: 0;
display: block;
position: fixed;
font-size: 1.6rem;
justify-content: space-around;
font-weight: normal;
height: 100vh;
width: 100%;
align-items: center;
text-decoration: none;
list-style:none;
opacity: 0;
transition: 0.5s;
pointer-events: none;
}
#menu li{
text-align: center;
margin: 40px 0;
}
#menu.active{
pointer-events: auto;
opacity: 100;
}
And this is what I did for the desktop resolution:
@media only screen and (min-width: 1000px) {
#menu{
padding: 0;
margin: 0;
display: flex;
position: fixed;
justify-content: space-between;
font-weight: normal;
height: 100px;
width: 40%;
align-items: center;
right: 100px;
text-decoration: none;
list-style:none;
opacity: 100%;
}
#menu li{
font-size: 1.2rem;
text-align: center;
z-index:9999999;
}
I don't know how to fix this without breaking my code for mobile and tablet resolutions.
Solution 1:[1]
Remove the Pointer events or comment it
#menu{
background-color: white;
margin: 60px 0 0 0;
padding: 0;
display: block;
position: fixed;
font-size: 1.6rem;
justify-content: space-around;
font-weight: normal;
height: 100vh;
width: 100%;
align-items: center;
text-decoration: none;
list-style:none;
opacity: 0;
transition: 0.5s;
/*pointer-events: none;*/
}
Solution 2:[2]
Use 'onclick' instead of 'onClick'.
You should use this because Javascript is case sensetive.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sahil Palad |
| Solution 2 | Shahriar Hasan Siam |
