我尝试使用 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 许可协议
更新(2022 年 12 月) :听起来,请尝试重新启动您的编辑器。我检查了所有内容(配置、导入),但没有用。当我重新启动我的编辑器 (VSCode) 时,类得到了识别。
原来的:
我遇到过同样的问题。它与您的 tailwind.config.js 有关确保您的 内容列表 指向使用 tailwind 的 html 文件。 (请参阅下面的代码以在下一级查看所有带有 html 的文件)
然后运行命令:
确保您不会收到任何有关无效路径的警告消息。