I have a situation where I want to change the background color immediately upon hovering over an element, and then revert back to the original color when no longer hovering. The CSS for this is straightforward:
#el {
background-color: black;
}
#el:hover {
background-color: gray;
}
However, I'm facing a challenge in trying to achieve an instant color change on click (active state), followed by a smooth transition effect when releasing the click.
#el:active {
background-color: green;
}
#el:hover:deactivate { /*this pseudo-class doesn't exist*/
background-color: gray;
transition: background-color 1s ease;
}
#el:deactivate { /*nor does this one*/
background-color: black;
transition: background-color 1s ease;
}
I've explored various options but haven't found a solution that allows me to apply the transition only on release without affecting hover behavior. Is there a way to accomplish this using pure CSS, without resorting to JavaScript?