Dro*_*rag 34 html css tailwind-css
我尝试使用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;
Run Code Online (Sandbox Code Playgroud)
在tailwind.config.js
theme: {
extend: {
// ...
},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
浏览器中的 HTML 结果:
Cod*_*ech 46
您只需更改 style.css 中的以下代码即可运行。
由此
@tailwind base;
@tailwind components;
@tailwind utilities;
Run Code Online (Sandbox Code Playgroud)
对此
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Run Code Online (Sandbox Code Playgroud)
其余代码保持不变。只需要更改上述内容即可。这通常发生在 Tailwind v3 中。
希望答案对您有帮助。
小智 34
更新(2022 年 12 月):顾名思义,请尝试重新启动编辑器。我检查了所有内容(配置、导入),但它不起作用。当我重新启动编辑器 (VSCode) 时,类被识别。
原来的:
我遇到过同样的问题。它与你的 tailwind.config.js 有关。确保你有指向使用 tailwind 的 html 文件的内容列表。(请参阅下面的代码以查看下一级带有 html 的所有文件)
然后运行命令:
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
Run Code Online (Sandbox Code Playgroud)
确保您不会收到任何有关无效路径的警告消息。
module.exports = {
content: ['./*/*.html', ],
theme: {
extend: {},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
san*_*ani 15
转到tailwind.config.js文件。在第一行,您会发现content,添加 html 文件的位置
module.exports = {
content: ['./index.html'],
theme: {
extend: {
primary : '#243c5a',
secondary : {
100: '#243c5a',
}
},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
转到 cmd 并运行命令npm run build-css来重建并显示代码中的任何错误。
在这里阅读更多内容
小智 5
我们需要编辑文件夹文件global.css
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Run Code Online (Sandbox Code Playgroud)
小智 5
一般来说,tailwindcss 不建议使用动态类,因为他们在文档中提到这里是一个链接。
\n\n\n不要动态构造类名:
\n
<div class="text-{{ error ? \'red\' : \'green\' }}-600"></div>\nRun Code Online (Sandbox Code Playgroud)\n在上面的示例中,字符串 text-red-600 和 text-green-600 不存在,因此 Tailwind 将不会生成这些类。
\n相反,请确保您使用的任何类名\xe2\x80\x99 都完整存在:
\n\n\n始终使用完整的类名
\n
<div class="{{ error ? \'text-red-600\' : \'text-green-600\' }}"></div>\nRun Code Online (Sandbox Code Playgroud)\n
小智 2
我看到您在代码中导入了“output.css”,但您必须导入 tailwind css 文件。前任:
<link rel="stylesheet" href="src/style.css">
Run Code Online (Sandbox Code Playgroud)
请参阅文档: https: //tailwindcss.com/docs/installation