Link Blinking If I put the cursor to that links

Viewed 58

Good day, there is some issue here hope anyone can help me out, when I hover to my menu links its start and always blinking it wont stop unless i remove the cursor on it. Also, when I hover the menu, the menu remove to its current position he gain another margin or padding i think it wont stay on where he is.

nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    height: 8rem;
    background-color: crimson;
}

nav .logo {
    display: inline-block;
    width: 50%;
    color: #ffffff;
    font-size: 3rem;
    font-weight: 800;
    margin-left: 3rem;
}

nav .logo h4 {
    display: inline-block;
}

nav .nav-link {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 50%;
    height: 6rem;
}

nav .nav-link ul li {
    display: inline-block;
    padding: 0 4rem;
    letter-spacing: 2px;
    transform: perspective(1px) translateZ(0);
    box-shadow: 0 0 1px rgba(117, 94, 94, 0);
    
}

nav .nav-link ul li a {
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
}

 nav .nav-link ul li:hover {
    text-align: center;
    cursor: pointer;
    background-color: #127681;
    color: #fff;
    padding: .8rem 1rem;
    border-radius: 25px;
    animation-name: hvr-push;
    animation-duration: 0.3s;
    animation-timing-function: linear;
    animation-iteration-count: 1;

}

@keyframes hvr-push {
    50% {
      transform: scale(0.8);
    }
    100% {
      transform: scale(1);
    }
  }
<nav>
        <div class="logo">
            <h4>Jury DEV</h4>
        </div>

        <div class="nav-link">
            <ul>
                <li><a class="active" href="">Home</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Contact</a></li>
            </ul>
        </div>
    </nav>

1 Answers

Problems with your code:

Problem 1: The li:hover should be a:hover (see code below). WHY? You must target the main element you want to hover in order to stop the blinking.

Problem 2: Elements that are inline that require block attributes (i.e. width, padding, height etc.) must have display: inline-block (see code below).

Problem 3: The anchor tags you were targeting did not have padding: .8rem 1rem but the hover selector did. So when your mouse hovered over them it would add padding: .8rem 1rem which caused the shift in position.

The code below is what I changed, everything else in your css did not have a direct effect in relation to your question.

nav .nav-link ul li {
    display: inline-block;
    padding: 0 3rem;
    letter-spacing: 2px;
    transform: perspective(1px) translateZ(0);
    box-shadow: 0 0 1px rgba(117, 94, 94, 0);

}

nav .nav-link ul li a {
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    text-align: center;
    padding: .8rem 1rem;
}

nav .nav-link ul {
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    padding: 0px;
}

 nav .nav-link ul li a:hover {
    display: inline-block;
    cursor: pointer;
    background-color: #127681;
    color: #fff;
    padding: .8rem 1rem;
    border-radius: 25px;
    animation-name: hvr-push;
    animation-duration: 0.3s;
    animation-timing-function: linear;
    animation-iteration-count: 1;

}

Hope this was helpful!

Related