I'm attempting to add a smooth underline effect to the links in my navbar when they are hovered over. Unfortunately, the entire ul element is being underlined instead of just the selected link.
Is there a way to resolve this issue?
a {
text-decoration: none;
color: black;
}
.nav a::before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: rgb(92, 149, 112);
visibility: hidden;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
.nav a:hover::before {
visibility: visible;
transform: scaleX(1);
}
ul.nav {
font-size: 11px;
list-style: none;
position: fixed;
display: block;
padding: 0;
margin: 0;
z-index: 100;
top: 0.5em;
right: 1.5em;
}
.nav li {
display: inline-block;
margin: 7px 15px;
}
.nav a:active::before {
visibility: visible;
transform: scaleX(1)
}
<ul class="nav">
<li id="nav-home"><a id="a-home" href="#">Home</a></li>
<li id="nav-services"><a href="#">Services</a></li>
<li id="nav-about"><a href="#">About</a></li>
<li id="nav-contact"><a href="#">Contact</a></li>
</ul>