【问题标题】:Why it says the `hover:` class does not exist. If `hover:` is a custom class, make sure it is defined within a `@layer` directive?为什么它说“悬停:”类不存在。如果 `hover:` 是一个自定义类,请确保它是在 `@layer` 指令中定义的?
【发布时间】:2021-08-25 18:17:54
【问题描述】:

我是前端开发的新手,我尝试构建新的 react-tailwindcss 项目。我的项目抛出错误,例如“hover: 类不存在。如果hover: 是自定义类,请确保它在@layer 指令中定义。”,知道吗?

global.css:

@tailwind base;
@tailwind components;
@tailwind utilities;


@layer components {
.icon{
    @apply hidden xl:inline-flex p-2 h-10 w-10 bg-gray-200 rounded-full text-gray-700 
cursor-pointer hover: bg-gray-300; 
}

.inputIcon{
    @apply  flex items-center space-x-1 hover: bg-gray-100
    flex-grow justify-center p-2 rounded-xl cursor-pointer ;
}
}

【问题讨论】:

  • 你安装了tailwind-css的包吗
  • @Skysoft13,是的,我愿意 :)
  • "hover:" 和样式之间不能有空格。例如,hover: bg-gray-100 应该是 hover:bg-gray-100
  • @CraigE,tnx 这么多:)

标签: reactjs tailwind-css


【解决方案1】:

悬停后删除空格:

hover:bg-gray-300

提示:: 我在 Visual Studio 代码 ctrl + k then ctrl + shift + s 上保存格式时遇到同样的问题

【讨论】:

    【解决方案2】:

    就我而言,我复制并粘贴了代码,@apply 之后有一个冒号 :,即

    .toggle-checkbox:checked {
      @apply: bg-primary;      // error due to ':' after @apply
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 1970-01-01
      • 2018-02-18
      • 2021-08-22
      • 2021-04-11
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      相关资源
      最近更新 更多