I’ve got this thing right now where I’ve got this sliding background on hover, and I find it a bit janky that all of the text changes colour at the same time. Can I somehow make it so that only the parts over the black background change colour?
a.nav {
font-family: Manrope;
font-weight: 400;
text-decoration: none;
color: #000;
background-image: linear-gradient(to bottom, transparent 1px, #000 1px);
background-repeat: no-repeat;
background-position-x: right;
background-size: 0%;
transition: background-size .15s;
}
a.nav:hover {
color: #fff;
background-size: 100%;
background-position-x: left;
}
<a class="nav">About us</a>
THANK YOU!!
2
Answers
I got half the solution posting here to help someone find the remaining 🙂 !
The problem lies with the
:hover
psuedoclass. You are saying, the moment the user hovers, change the text color to white. However, since this applies it to all the text, and the text is one element, you could do a workaround, by creating multiple elements for each text. But this could take a while and not be efficient. Instead, use keyframes: