Replies: 1 comment 2 replies
-
Hey @diegohaz good to see you! So two options here… First, you might not actually need to worry about this at all — we sort all of your utilities intelligently based on the number of properties they use, so a class like In this example, https://play.tailwindcss.com/CV7RwW9Ftu If you really need them to be in a separate layer, another option is to nest the layer: @utility button {
@layer base {
@apply bg-black …;
}
} This will produce CSS that ultimately is interpreted like this in the browser: @layer utilities {
@layer base {
.button { ... }
}
.flex { ... }
.bg-red-500 { ... }
} Since all rules not in a layer are treated as more important than rules in a layer, using a nested layer effectively behaves the same as this for all intents and purposes: @layer base-utilities {
.button { ... }
}
@layer utilities {
.flex { ... }
.bg-red-500 { ... }
} Let me know if that helps! |
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.
-
I'd like to define the cascade layer to add my utility. This will help me create base utilities that can be overridden by existing utility classes applied to the element. Something like this:
This way, I can consistently override some of its properties using built-in Tailwind utilities in HTML:
I could avoid using
@utility
entirely and simply define a CSS class, but then I'd miss out on the autocomplete, variants, and nice DX provided by Tailwind classes.Beta Was this translation helpful? Give feedback.
All reactions