CSS KP 05— Nav hover over indicator, <ul><li><a> or <button> with aria
<section class="flow" id="interactive-elements">
<h2 class="numbered-title"><span>03</span> Interactive elements</h2>
<!-- navigation -->
<div>
<nav>
<ul>
<li><a>Active</a></li>
<li><a>Hovered</a></li>
<li><a>Idle</a></li>
</ul>
</nav>
</div>
By utilizing the utility classes we built in our previous blog, we can directly go to our HTML and add styling.
<section class="flow" id="interactive-elements">
<h2 class="numbered-title"><span>03</span> Interactive elements</h2>
<!-- navigation -->
<div>
<nav>
<ul class="primary-navigation flex" style="--gap: 4rem;">
<li><a class="uppercase text-white letter-spacing-2" href="#">Active</a>
<li><a class="uppercase text-white letter-spacing-2" href="#">Hovered</a>
<li><a class="uppercase text-white letter-spacing-2" href="#">Idle</a>
</ul>
</nav>
</div>
add custom css
.primary-navigation {
--gap: 8rem;
list-style-type: none;
padding: 0;
margin: 0;
}
.primary-navigation a {
text-decoration: none;
}
add span for the number
//html
<ul class="primary-navigation flex">
<li><a class="uppercase text-white letter-spacing-2" href="#"><span>1</span>Active</a>
<li><a class="uppercase text-white letter-spacing-2" href="#"><span>2</span>Hovered</a>
<li><a class="uppercase text-white letter-spacing-2" href="#"><span>3</span>Idle</a>
</ul>
css
//css
.primary-navigation a > span {
font-weight: 700;
margin-right: .5rem;
}
add underline-indicators
custom component css. and add “active
” class to li
.
//html
<ul class="primary-navigation underline-indicators flex">
<li class="active"><a class="uppercase text-white letter-spacing-2" href="#"><span>1</span>Active</a>
.primary-navigation { //parent element
...
--underline-gap: 2rem;
...
}
.underline-indicators > * { //all child elements
padding: var(--underline-gap, 1rem) 0; //default
border-bottom: .3rem solid hsl( var(--clr-white) );
}
Now hide them all
//css
.underline-indicators > * {
...
border-bottom: .3rem solid hsl( var(--clr-white) / 0 ); // <--add
// `/0` to hide
}
then add the hover affect
//css
.underline-indicators > *:hover {
border-color: hsl( var(--clr-white) / .25); //25% opacity
}
Utilize that active class
.underline-indicators > *:hover {
border-color: hsl( var(--clr-white) / .25); //25% opacity
}
.underline-indicators > .active {
border-color: hsl( var(--clr-white) / 1 ); //100% opacity
}
<div style="margin-bottom: 50vh">
<!-- Tabs -->
<div class="tap-navigation flex">
<div>
<button class = "active uppercase .ff-sans-cond text-white bg-dark letter-spacing-1">Moon</button>
<button class = "uppercase .ff-sans-cond text-white bg-dark letter-spacing-1">Mars</button>
<button class = "uppercase .ff-sans-cond text-white bg-dark letter-spacing-1">Europa</button>
</div>
</div>
- add all the utility class css we’ve wrote
- add “underline-indicators” to the parent div
//html
<div class="tap-navigation flex">
<div class = "underline-indicators" > ///<-------- add
<button.....
.underline-indicators > * {
padding: var(--underline-gap, 1rem) 0;
border: 0; // <---- just add 0
border-bottom: .2rem solid hsl( var(--clr-white) / 0 );
}
Accessibility, Accessible Rich Internet Applications ARIA
Accessible Rich Internet Application provides additional semantic information for the assistive technologies such as screen readers, to better understand .
.underline-indicators > [aria-selected="true"]