【问题标题】:Tailwind's directive @apply not working on NuxtTailwind 的指令 @apply 不适用于 Nuxt
【发布时间】:2020-08-07 23:10:16
【问题描述】:

我正在尝试在我的全新项目中使用 Tailwind,每个实用程序都可以正常工作,但 @apply 甚至无法编译。

这是错误信息:

Syntax Error: SyntaxError                                                                                                                                                                                                                                       friendly-errors 08:12:30

(5:5) `@apply` cannot be used with `.lg\:mt-0` because `.lg\:mt-0` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that `.lg\:mt-0` 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.

  3 | @import 'tailwindcss/components';
  4 | .navbar-item-link {
> 5 |     @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
    |     ^
  6 | }
  7 | /* purgecss end ignore */

我的 tailwind.css 文件:

/* purgecss start ignore */
@import 'tailwindcss/base';
@import 'tailwindcss/components';
.navbar-item-link {
    @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
}
/* purgecss end ignore */

@import 'tailwindcss/utilities';

我已经安装了 postcss cli 并像这样使用 postcss.config.js:

module.exports = {
  plugins: [
    require("postcss-import"),
    require("tailwindcss"),
    require("autoprefixer")
  ]
};

但这些都不起作用。

【问题讨论】:

    标签: css nuxt.js tailwind-css


    【解决方案1】:

    @apply 方法不能使用伪类前缀

    不是这个

    .navbar-item-link {
        @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
    }
    

    你应该使用这样的东西:

    // Normal State
    .navbar-item-link {
        @apply text-xs mt-1 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100;
    }
    
    // Hover State
    navbar-item-link:hover{
        @apply border-blue-best-100;
    }
    
    // Large Screen
    @screen lg {
        .navbar-item-link{
            @apply mt-0;
        }
    }
    

    这里有更多关于它的信息

    https://tailwindcss.com/docs/extracting-components/#extracting-css-components-with-apply

    https://tailwindcss.com/docs/functions-and-directives/#screen

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 2023-03-27
      • 2022-08-14
      • 2023-03-12
      • 2021-12-17
      • 2022-11-16
      • 2021-04-15
      • 2022-12-10
      • 2022-08-17
      相关资源
      最近更新 更多