我想在tailwind的next.js项目中使用自定义类overflow:inherit
,并将其作为@apply overflow-inherit
使用,但这会导致错误。然而,我可以使用预构建的tailwind类,例如@apply flex flex-col md:h-full h-screen;
,但不能使用自定义类。
完整的repo:https://github1s.com/GorvGoyl/Personal-Site-Gourav.io
tailwind.scss:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer utilities {
@variants responsive {
.overflow-inherit {
overflow: inherit;
}
}
}
项目.module.scss:
.css {
:global {
.wrapper-outer {
@apply overflow-inherit; //trying to apply custom utility
}
}
}
错误:
wait - compiling...
event - build page: /next/dist/pages/_error
error - ./layouts/css/project.module.scss:4:6
Syntax error: C:\Users\1gour\Personal-Site\project.module.scss The `overflow-inherit` class does not exist, but `overflow-hidden` does. If you're sure that `overflow-inherit` exists, make sure that any `@import` statements are being properly processed before Tailwind CSS sees your CSS, as `@apply` can only be used for classes in the same CSS tree.
2 | :global {
3 | .wrapper-outer {
> 4 | @apply overflow-inherit;
| ^
5 | }
6 | }
postcss.config.js:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
- "下一个版本": "^10.0.7",
- "Tailwind CSS": "^2.0.3",
- "Sass": "^1.32.8",
- "PostCSS": "^8.2.6",
@apply overflow-inherit
之前就调用了它,因为SASS使用自上而下的控制流。即使导入模块,它们也应该按顺序导入。 - Leo