I want the first item in a list in my navigation to stay underlined, and the rest to underline on hover, with the first item only not underlining until I hover on another list item. I have already tried the first child selector to try ad it but it does not seem to work.
.nav__links a {
padding-block: 5px;
color: var(--text-dark);
border-bottom: 3px solid transparent;
}
.nav__links a:hover {
border-color: var(--btn-primary-color);
}
<ul class="nav__links" id="nav-links">
<li><a href="#home">HOME</a></li>
<li><a href="#company">COMPANY</a></li>
<li><a href="#services">SERVICES</a></li>
<li><a href="#contact">CONTACT</a></li>
<li class="nav__links__btn nav__remove__btn">
<button class="btn">CONTACT US</button>
</li>
<li class="nav__links__btn nav__remove__btn">
<button class="btn">GET A FREE QUOTE</button>
</li>
</ul>
I have already tried the child selector on the first li item but had no luck. I’m a bit unsure of how to approach it.
.nav__links a {
padding-block: 5px;
color: var(--text-dark);
border-bottom: 3px solid transparent;
}
.nav__links a:hover {
border-color: var(--btn-primary-color);
}
2
Answers
As below.
The first child and any hovered item gets the border.
If the first child has any sibling that is hovered, its border is removed.