not able to use custom classes in @apply in scss file tailwind nextjs project?(不能在SCSS文件顺风nextjs项目中使用@Apply中的自定义类吗?)
问题描述
我正在尝试使用自定义类overflow:inherit作为tailwindnext.js项目中的@apply overflow-inherit,但它引发错误。但是,我可以@apply像@apply flex flex-col md:h-full h-screen;这样预先构建顺风类,但不能自定义。
完全回购:https://github1s.com/GorvGoyl/Personal-Site-Gourav.io
trawind.scss:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer utilities {
@variants responsive {
.overflow-inherit {
overflow: inherit;
}
}
}
project.module e.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:Users1gourPersonal-Siteproject.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";,
- ";trawincss";:";^2.0.3";,
- ";sass";:";^1.32.8";,
- ";Postcss";:";^8.2.6";,
推荐答案
我在我的Laravel项目中遇到了同样的问题。
我认为postcss对我来说是不够的。因此,在webpack.mix.js中,我删除了以下
mix.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]);
并将其替换为sass,如下所示
mix.sass("resources/css/app.scss", "public/css").options({
postCss: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
], });
现在,我有很多很酷的功能,包括您想要的
我甚至不需要使用@layer
在我的SCSS文件中,我可以组合@apply和@extend,它可以工作
.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;
}
这篇关于不能在SCSS文件顺风nextjs项目中使用@Apply中的自定义类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不能在SCSS文件顺风nextjs项目中使用@Apply中的自定义类吗?
基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
