Is there any way to remove class once the object is hovered using tailwind classes?
<span className='group inline-block relative'>
Hello
<span className='hidden absolute -top-16 left-16 group-hover:inline-block'>-</span>
</span>
Here I want to remove the hidden
class once the object is hovered which means it would be hidden at first(when the page is loaded) but once it is hovered the object stays put.
Before:
Result needed:
2
Answers
To add a class on hover using tailwind, you can use the :hover pseudo-class. For example, if you wanted to add the class "hover:bg-red" to an element when the user hovers over it, you would use the following CSS:
.selector:hover { class:bg-red; }
To remove a class on hover using tailwind, you can use the :not(:hover) pseudo-class. For example, if you wanted to remove the class "hover:bg-red" from an element when the user hovers over it, you would use the following CSS:
.selector:not(:hover) { class:bg-red; }
You can do something like this.
Use
group
class to group the elements and then addgroup-hover:flex
to display that subsequent child element. Else remain that child to behidden