Tailwind CSS Styles Not Applying Inside @layer components in Next.js Project
Answered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
I'm facing an issue with Tailwind CSS in my Next.js project where styles defined within the @layer components directive are not being applied. However, when the same styles are placed outside the @layer directive, they work perfectly. Here's the relevant code:
Complete beginner who has tried everything before ending up here 😦
```
/* Not working when inside @layer /
&913086567042674719 base;
&913086567042674719 components;
&913086567042674719 utilities;
@layer components {
h1.bold {
@apply text-[30px] font-bold;
}
}
/ Working when placed outside @layer */
h1.bold {
@apply text-[30px] font-bold;
}
```
```
postcss-import
module.exports = {
plugins: {
'postcss-import': {},
tailwindcss: {},
autoprefixer: {},
},
}
```
Complete beginner who has tried everything before ending up here 😦
```
/* Not working when inside @layer /
&913086567042674719 base;
&913086567042674719 components;
&913086567042674719 utilities;
@layer components {
h1.bold {
@apply text-[30px] font-bold;
}
}
/ Working when placed outside @layer */
h1.bold {
@apply text-[30px] font-bold;
}
```
```
postcss-import
module.exports = {
plugins: {
'postcss-import': {},
tailwindcss: {},
autoprefixer: {},
},
}
```
Answered by Common paper wasp
Just tried in my project and it works as expected. Check your tailwind.config file it should contains
content section: content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./shared/**/*.{js,ts,jsx,tsx,mdx}",
],2 Replies
Common paper wasp
Just tried in my project and it works as expected. Check your tailwind.config file it should contains
content section: content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./shared/**/*.{js,ts,jsx,tsx,mdx}",
],Answer
Northeast Congo LionOP
it worked. Thanks!