I’m trying to style a button with tailwind on Next.js.
I want the button background color to change on hover.
I’m trying to style a button doing something like this
<button className="rounded-full bg-gradient-to-br from-cyan-300 via-blue-500 to-purple-500 hover:bg-slate-200">
Hire Me
</button>
But hover is not changing the background color.
2
Answers
Because the gradient color sets the background by default, to solve this issue, you can use the same gradient but with the desired color on hover, like below:
This should solve the problem and ensure the gradient background changes correctly on hover.
Tailwind bg-gradient-* class sets a linear gradient (in this case) like the following CSS code
since hover:bg-slate-200 only affects the background color, the background-image is unaltered. you have to modify the background-image to get the desired result
override the background-image property by setting
hover:bg-none
first