Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover effect makes unwanted changes on UI

Tags:

html

css

I'm creating my first navigation bar but it's not working expected. How can I remain the main UL element and not increase their sizing if I want to hover the li element?

I tried to add in ul li a margin:0 but still, it didn't work.

I wanted to have different styling when I hover those li, but the blue background changed as well, what I wanted is to remain the .links as is so that only the change will take effect on the li when I hover it.

nav {
    width: 100%;
    height: 60px;
    max-width: 1200px;
    margin:  0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

li {
    list-style: none;
}

nav .logo a {
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
}

nav .links {
    display: flex;
    gap: 2rem;
    background: #00ABE4 ;
    padding: 10px 20px;
}

nav .toggle-btn {
    color: #00ABE4 ;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
}

.nav-btn {
    background: #00ABE4 ;
    color: #fff;
    padding:  0.5rem 1rem;
    border: none;
    outline: none;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: scale 0.2 ease-in-out;
}

.nav-btn:hover {
    scale: 1.05;
    color: #fff;
}

ul > li:hover {
    background: #000;
    padding: 5px ;
    transition: all 0.2s ease;
    
}

nav .nav-btn:active {
    scale: 0.95;
}
 <header>
            <nav>
                <div class="logo">
                    <a href="#">Jury Mini</a>
                </div>
                <ul class="links">
                    <li><a href="hero">Home</a></li>
                    <li><a href="">About</a></li>
                    <li><a href="hero">Services</a></li>
                    <li><a href="hero">Contact</a></li>
                </ul>
                <a href="#" class="nav-btn">Get Started</a>
                <div class="toggle-btn"><i class="fa-solid fa-bars"></i></div>
            </nav>
          
        </header>
like image 436
JDEV Avatar asked Nov 18 '25 11:11

JDEV


1 Answers

I added this codes to your css :

ul li {
list-style-type:none
}

ul li a {
text-decoration:none;
padding:10px;
}

ul li a:hover {
text-decoration:none;
padding:10px;
background: #000;
transition: all 0.5s ease-out;
color:#fff;
}


and deleted ul > li:hover class, added width:100vw for nav .Finally added justify-content:center; align-items:center; to nav .links class

nav {
    width: 100vw;
    height: 60px;
    max-width: 1200px;
    margin:  0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

li {
    list-style: none;
}

nav .logo a {
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
}

nav .links {
    display: flex;
    justify-content:center;
    align-items:center;
    gap: 2rem;
    background: #00ABE4 ;
    padding: 10px 20px;
}

nav .toggle-btn {
    color: #00ABE4 ;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
}

.nav-btn {
    background: #00ABE4 ;
    color: #fff;
    padding:  0.5rem 1rem;
    border: none;
    outline: none;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: scale 0.2 ease-in-out;
}

.nav-btn:hover {
    scale: 1.05;
    color: #fff;
}

ul li {
list-style-type:none
}

ul li a {
text-decoration:none;
padding:10px;
}

ul li a:hover {
text-decoration:none;
padding:10px;
background: #000;
transition: all 0.5s ease-out;
color:#fff;
}


nav .nav-btn:active {
    scale: 0.95;
}
<header>
  <nav>
    <div class="logo">
      <a href="#">Jury Mini</a>
    </div>
    <ul class="links">
      <li><a href="hero">Home</a></li>
      <li><a href="">About</a></li>
      <li><a href="hero">Services</a></li>
      <li><a href="hero">Contact</a></li>
    </ul>
    <a href="#" class="nav-btn">Get Started</a>
    <div class="toggle-btn"><i class="fa-solid fa-bars"></i></div>
  </nav>
</header>
like image 58
webworm84 Avatar answered Nov 20 '25 01:11

webworm84