I want to make a CSS underline animation on my website’s navigation, like the one on poosh.com. I have no idea how I make it so that only the navigation items are underlined. Hope y’all understand what I mean.
I tried this:
nav ul {
display: inline-block;
position: relative;
color: #000000;
}
nav ul::after {
content: '';
position: relative;
width: 100%;
transform: scaleX(0);
height: 1px;
bottom: 12px;
left: 0;
background-color: #000000;
transform-origin: bottom left;
transition: transform 0.3s ease-out;
}
nav a:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
but it doesn’t work.
4
Answers
You have to
li
afterul
like this:Changes made:
Removing the
::after
from theul
, as we want to add the underline to thea
tags instead.Changing the bottom property of the
::after
to-2px
, as we want to position the underline just below the text.Removing the
transform-origin
property fromnav a:hover::after
, as it’s not needed for the animation.Example HTML:
Hope this helps!
Here we go: