-
Docs says in v4 base and components layers are still defined with https://tailwindcss.com/docs/adding-custom-styles#adding-base-styles Practically it means I am forced to define all base, components and utilities layers with I could define all layers with @import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/base.css" layer(base);
@import "tailwindcss/components.css" layer(components);
@import "tailwindcss/utilities.css" layer(utilities); So at the end how to do this in v4? I already have a lot of code that uses custom classes with I saw similar Github issues without obvious solution. If I use You can see my styles code here: https://github.com/nemanjam/nemanjam.github.io/tree/feat/tailwind4-v2/src/styles |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
In v4, Tailwind doesn't "hijack" the
You'd need to use You can use @utility foo {
@layer base {
…
}
} Ideally, you'd use your templates to define the components, instead of writing any CSS. Adam Wathan (creator of Tailwind) does seem to advocate avoiding |
Beta Was this translation helpful? Give feedback.
-
If I do it like that:
@utility tags-utility {
@layer base {
.b-h1 {
@apply text-3xl sm:text-4xl md:text-5xl;
@apply font-bold;
@apply mb-6 md:mb-8 lg:mb-10;
}
.b-h2 {
@apply text-2xl md:text-3xl;
@apply font-bold;
@apply mt-12 mb-6 md:mt-14 md:mb-8;
}
// ... other classes
}
} |
Beta Was this translation helpful? Give feedback.
-
Will I achieve the same effect just by using @import "tailwindcss/base.css" layer(base); |
Beta Was this translation helpful? Give feedback.
-
I was surprised to find out today that @layer components {
.input {
@apply ...;
}
} I thought that's natural expectation. We don't want to turn simple HTML elements into components. |
Beta Was this translation helpful? Give feedback.
The must match of of these two regular expressions:
tailwindcss/packages/tailwindcss/src/utilities.ts
Lines 29 to 30 in 7005ad7
The name is the class name that you'd use.
I'm not sure where this "namespace" concept has come from, but for
b-h1
, you'd do: