I'm trying to use a custom class overflow:inherit
as @apply overflow-inherit
in tailwind
next.js
project but it's throwing error. However, I can @apply
pre-built tailwind classes like @apply flex flex-col md:h-full h-screen;
but not custom.
Full 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;
}
}
}
project.module.scss:
.css {
:global {
.wrapper-outer {
@apply overflow-inherit; //trying to apply custom utility
}
}
}
Error:
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: {},
},
};
I had the same problem on my Laravel project.
I decided that postcss
is not enough for me. So in the webpack.mix.js
I deleted the following
mix.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]);
and replaced it with sass
like this
mix.sass("resources/css/app.scss", "public/css").options({
postCss: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
], });
Now, I got a number of cool features including the one you want
I don't even need to use @layer
in my scss file I can combine @apply
and @extend
and it works
.btn-my-theme{
@apply rounded border py-2 px-3 shadow-md hover:shadow-lg;
}
.btn-my-primary{
@extend .btn-my-theme;
@apply text-blue-600 bg-blue-200 hover:bg-blue-100 border-blue-500;
}
.btn-my-secondary{
@extend .btn-my-theme;
@apply text-gray-600 bg-gray-200 hover:bg-gray-100 border-gray-500;
}
Set CSS validate in "Workspace/.vscode/settings.json"
"css.validate": false,
or "User/settings.json"
"css.validate": false,
like this link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.