Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

navbar items shaking on hover

I am new to learning web designing. I am creating a sample website for my practice. I am stuck on the navbar item issue. after adding a hover effect on list items my items start shaking when I hover on them.

Here is my code:

<nav>
            <div>
            </div>
            <ul>
                <li><a>one</a></li>
                <li><a>two</a></li>
                <li><a>three</a></li>
            </ul>
        </nav>

CSS style:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

nav {
    display: flex;
    justify-content: space-around;
    flex-direction: row;
    align-content: center;
    align-items: center;
    width: 100%;
    background-color: #a33454;
}

nav div {
    height: 60px;
    width: 150px;
    margin: 0.5rem;
}

nav ul {
    display: flex;
    list-style: none;
    justify-content: space-between;
    margin: 0.5rem;
    align-items: center;
    align-content: center;
}

nav ul li {
    font-size: 1.3rem;
    padding: 0.5rem;
    margin: 0.2rem 0.6rem;
}

nav ul li:hover{
    border-bottom: 4px solid #022222;
}

I also created a sandbox demo

>Solution :

This is happening due to the border-bottom which appears when hovering. That is adding 4px to the height.

The best way around it is to also have a border in the not-hovered state but make it invisible.

nav ul li {
    font-size: 1.3rem;
    padding: 0.5rem;
    margin: 0.2rem 0.6rem;
    border-bottom: 4px solid transparent;
}

nav ul li:hover{
    border-bottom: 4px solid #022222;
}

By setting color to transparent, it will be invisible.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading