Is it possible to change the color of the underline in an <a>
tag when hovering over it?
After some investigation, it seems that direct color changes are not feasible. Instead, you can use the border-bottom
option. However, my attempt did not yield any results when tested on Chrome while hovering over it.
.nav-main {
width:100%;
background-color: #222;
height:70px;
color:#fff;
display:flex;
justify-content: center;
}
.nav-main > ul {
margin:0;
float:left;
list-style-type: none;
}
.nav-main > ul > li {
float:left;
padding-left: 10px;
}
.nav-item {
display:inline-block;
padding:15px 20px;
height:40px;
line-height:40px;
color:#fff;
text-decoration:none;
}
.nav-item:hover {
border-bottom-color: #00cc00;
}
<nav class="nav-main" id="navMain">
<ul>
<li>
<a href="#" class="nav-item"> HOME</a>
</li>
<li>
<a href="#" class="nav-item">ABOUT US </a>
</li>
<li>
<a href="#" class="nav-item">PORTFOLIO </a>
</li>
<li>
<a href="#" class="nav-item">SERVICES </a>
</li>
<li>
<a href="#" class="nav-item">CONTACT US </a>
</li>
</ul>
</nav>
JS FIDDLE