Home > Software engineering >  My navbar links aren't clickable, can someone help me?
My navbar links aren't clickable, can someone help me?

Time:02-08

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. Does anyone know why? Can someone please help me? This is the code i've created. Thanks.

* {
    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 >
            <li><a href="home.html">Home</a></li>
            <li><a href="home.html">Lessen</a></li>
        </ul>

        <img src="img/logo.png">

        <ul >
            <li><a href="home.html">Over ons</a></li>
            <li><a href="home.html">Contact</a></li>
        </ul>
</nav>



    <header>
        <div >
            <div ></div>
            <video 
            loop
            muted
            autoplay
            preload="auto"
            src="img/promo.mp4"
            alt="Promotiefilmpje sportschool Burning Heart">
            </video>
        </div>
    </header>

CodePudding user response:

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"

CodePudding user response:

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 >
            <li><a href="home.html">Home</a></li>
            <li><a href="home.html">Lessen</a></li>
        </ul>

        <img src="img/logo.png">

        <ul >
            <li><a href="home.html">Over ons</a></li>
            <li><a href="home.html">Contact</a></li>
        </ul>
</nav>



    <header>
        <div >
            <div ></div>
            <video 
            loop
            muted
            autoplay
            preload="auto"
            src="img/promo.mp4"
            alt="Promotiefilmpje sportschool Burning Heart">
            </video>
        </div>
    </header>

  •  Tags:  
  • Related