|
Hello guys, I have created a simple button with hover effect which changes text color on hover or it should have but the hover effect is not properly applied and even the cursor is not changing for button. When I switch to the previous version v3.4.17 its working just fine. Is it a bug or am I doing something wrong here? Here is the code link in latest tailwind play: |
Replies: 6 comments 14 replies
|
Some things:
|
|
I found solution in the https://tailwindcss.com/docs/upgrade-guide If laptop is touch screen and v4 "thinks" it doesn't have the ability to hover... the solution they propose is to add to the main css file: "@custom-variant hover (&:hover);" it can for try it. |
|
@Reconfort solved it for me. Got the issue on my mac book m1 max inside my electron react app |
|
Adding a custom variant fixed it for me. Try reinstalling Tailwind (latest
version v4.1.8) and using Vite if you haven't already.
…On Mon, Jun 2, 2025, 9:30 PM Casey Shore ***@***.***> wrote:
What was the solution?
—
Reply to this email directly, view it on GitHub
<#17225 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BAGFTY42LTT6QEGPQ2K4HHL3BSJ2ZAVCNFSM6AAAAABZCXVMFSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGMZUGY4TMNQ>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
|
The fix above All of the media queries below, run from the console for testing, returned false on the device. Just one of them returning true could've handled the "it's a desktop/laptop, but it has a touch screen" which would then let you go "enable hover".
It's a laptop with a touch screen, but still a laptop. I wanted hover to work. I decided to rely on Tailwind breakpoints, as defined here. I went with anything less than 768px is a mobile device, anything greater or equal is a desktop/laptop/something else that gets to have hover. It isn't perfect, but it covers most cases. /*
Override Tailwind v4's default hover variant.
Tailwind v4 uses @media (hover: hover) which fails on hybrid devices
(touchscreen laptops) where the browser reports touch as primary input.
Hover is enabled on desktop (>= 768px) and disabled on mobile (< 768px).
768px is the tailwind md breakpoint defined at https://tailwindcss.com/docs/responsive-design#overview
*/
@custom-variant hover {
@media (width >= 768px) {
&:hover {
@slot;
}
}
} |
|
I fixed it by overriding it with @custom-variant hover {
@media (any-hover: hover) {
&:hover {
@slot;
}
}
} |
I found solution in the https://tailwindcss.com/docs/upgrade-guide
"In v4 Tailwind team updated the hover variant to only apply when the primary input device supports hover:"
If laptop is touch screen and v4 "thinks" it doesn't have the ability to hover... the solution they propose is to add to the main css file:
"@custom-variant hover (&:hover);"
it can for try it.