-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hover style cannot override group-hover style #3527
Comments
In your example, the classes are the same for both divs, so obviously they behave the same. You mentioned already that specificity causes
|
@richadr I was exploring a datagrid solution with My point here is, the variant order defines the order of CSS output, thus defines the rule overriding precedence. So we could use classes to set different styles for different states on the same class attr like this: <input class="bg-gray-50 hover:bg-gray-100 focus:bg-yellow-200"> In the default config, But things are not the same for group-hover. I'm thinking that it is possible to generate a group-prefixed version of group-hover selectors to even the specificities maybe? |
This is just due to the nature of the selector specificity as mentioned. Duplicate of #3376. |
Here are some more details on how to prioritize child vs parent group styling: |
How would one solve this with properties that can't be overridden by children? e.g. opacity e.g. <div className="group"> <!-- cannot apply opacity here without affecting the img element below -->
<img src="avatar.png">
<button className="opacity-0 group-hover:opacity-50 hover:opacity-100">⭐️</button>
</div> ✅ Use a second group, to match (and therefore beat) the specificity of the parent: <div className="group">
<img src="avatar.png">
<span className="group/star">
<button className="opacity-0 group-hover:opacity-50 group-hover/star:opacity-100">⭐️</button>
</span>
</div> Update: This fix isn't reliable since Tailwind doesn't guarantee rule order, and has switched places on me, breaking my fix. |
@JonAbrams +1 with this problem |
I need the group-hover's color ON button when parent div is hovered over and that's working fine. However, when the button itself is hovered over, I want a different shade, but the above solutions won't help with that. |
Describe the problem:
Say this HTML:
When hovering on the "lorem" div, I expect "lorem" to be red and "Ipsum" to be blue.
But nothing goes red. Because the specificity of group-hover selector is bigger than hover selector (3 vs 2, due to the
.group
class).I'm not really sure if this is a bug. But
hover
appears aftergroup-hover
in the default variant configuration, so I feel like that hover should override group-hover's effect.Link to a minimal reproduction:
https://play.tailwindcss.com/QmLT8HgjhB
The text was updated successfully, but these errors were encountered: