Replies: 1 comment 1 reply
-
|
For variants, I think it's rare that you would need to repeat utilities for different variants. Grouping, in my opinion, is much more common: In your case, I think it's simpler to declare a new variant to merge the existing two variants. @import "tailwindcss";
@custom-variant hover-and-focus-visible {
@variant hover {
@slot;
}
@variant focus-visible {
@slot;
}
}
@layer base {
button {
color: white;
background-color: grey;
padding: 4px;
@variant hover-and-focus-visible {
background-color: red;
}
}
}This would also work with the current inline HTML syntax. <div class="hover:bg-red-500 focus-visible:bg-red-500">...</div>
<div class="hover-and-focus-visible:bg-red-500">...</div>But of course, extending the inline HTML syntax is harder, because it would bloat the generated CSS. (See more: #8337 (reply in thread)) With The best approach, in any case, is to use inline HTML:
Tip Always use the appropriate CSS layer. Unlayered CSS is too strong, and TailwindCSS utilities won't be able to override it later. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
if I do something like this in css
i get an error like
Cannot use@variantwith unknown variant: variant1, variant2tailwind play example
I am used to being able to apply styles to multiple comma-separated things in css e.g.
It would be cool if I could do the same with tailwind variants.
if this is deemed valuable, i'd be very interested in contributing/implementing this feature.
Beta Was this translation helpful? Give feedback.
All reactions