安装后 Tailwind 类不工作

新手上路,请多包涵

我尝试使用 CSS,我只是用 npm 安装 tailwindcss,然后我构建 css 并提供 output.css。但是,当我在按钮中使用 bg-black 类进行测试时,它仍然无法正常工作。

我使用的构建命令 tailwindcss -i ./src/style.css -o ./dist/output.css 我把它放到package.json的脚本中

目录文件路径:

在此处输入图像描述

src/style.css

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

tailwind.config.js

     theme: {
      extend: {
        // ...
      },
    },
    plugins: [],
  }

dist/index.html

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="output.css">
    <title>Learn Tailwind</title>
</head>
<body>
    <div class="container">
        <button class="bg-black">Awesome</button>
    </div>
</body>
</html>

浏览器中的 HTML 结果:

在此处输入图像描述

原文由 Drok Brag 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 421
1 个回答

更新(2022 年 12 月) :听起来,请尝试重新启动您的编辑器。我检查了所有内容(配置、导入),但没有用。当我重新启动我的编辑器 (VSCode) 时,类得到了识别。

原来的:

我遇到过同样的问题。它与您的 tailwind.config.js 有关确保您的 内容列表 指向使用 tailwind 的 html 文件。 (请参阅下面的代码以在下一级查看所有带有 html 的文件)

然后运行命令:

 npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

确保您不会收到任何有关无效路径的警告消息。

 module.exports = {
  content: ['./*/*.html', ],
  theme: {
    extend: {},
  },
  plugins: [],
}

原文由 Matt Stevens 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题