'How can I find out why my navbar links aren't clickable?
My navbar links aren't clickable and I can't figure out why. I'm trying to create a hero video with a black gradient on top of it. The navbar is transparant and the logo is aligned in the middle. My navbar links aren't working, I can't click them. How can I find out why?
This is the code I've created.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
li {
list-style-type: none;
}
a {
text-decoration: none;
color: white;
}
nav {
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.2);
min-height: 5vh;
position: absolute;
}
nav img {
width: 15%;
height: 15%;
}
.nav-links {
display: flex;
margin: 0px 20px;
}
.nav-links li {
margin: 0px 5vh;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 14px;
}
.nav-links li:hover {
cursor: pointer;
}
/***** Index *****/
/* Hero */
.index-hero video {
width: 100%;
height: 100vh;
object-fit:cover;
}
.gradient {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: linear-gradient(180deg,#000000 0%,#000000 100%);
opacity: 0.5;
}
<nav>
<ul class="nav-links">
<li><a href="home.html">Home</a></li>
<li><a href="home.html">Lessen</a></li>
</ul>
<img src="img/logo.png">
<ul class="nav-links">
<li><a href="home.html">Over ons</a></li>
<li><a href="home.html">Contact</a></li>
</ul>
</nav>
<header>
<div class="index-hero">
<div class="gradient"></div>
<video
loop
muted
autoplay
preload="auto"
src="img/promo.mp4"
alt="Promotiefilmpje sportschool Burning Heart">
</video>
</div>
</header>
Solution 1:[1]
Seems like your .gradient element is covering everything else because of its absolute position. You can either define position: relative for header to make that the relative anchor of its .gradient child (which otherwise willl be body - hence the covering), o you can add pointer-events: none to .gradient to "let clicks go though it"
Solution 2:[2]
Add z-index:1; to your navbar element in css code.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
li {
list-style-type: none;
}
a {
text-decoration: none;
color: white;
}
nav {
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.2);
min-height: 5vh;
position: absolute;
z-index:1;
}
nav img {
width: 15%;
height: 15%;
}
.nav-links {
display: flex;
margin: 0px 20px;
}
.nav-links li {
margin: 0px 5vh;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 14px;
}
.nav-links li:hover {
cursor: pointer;
}
/***** Index *****/
/* Hero */
.index-hero video {
width: 100%;
height: 100vh;
object-fit:cover;
}
.gradient {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: linear-gradient(180deg,#000000 0%,#000000 100%);
opacity: 0.5;
}
<nav>
<ul class="nav-links">
<li><a href="home.html">Home</a></li>
<li><a href="home.html">Lessen</a></li>
</ul>
<img src="img/logo.png">
<ul class="nav-links">
<li><a href="home.html">Over ons</a></li>
<li><a href="home.html">Contact</a></li>
</ul>
</nav>
<header>
<div class="index-hero">
<div class="gradient"></div>
<video
loop
muted
autoplay
preload="auto"
src="img/promo.mp4"
alt="Promotiefilmpje sportschool Burning Heart">
</video>
</div>
</header>
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 | Johannes |
| Solution 2 | srinithi R |
