【发布时间】:2022-08-22 21:37:06
【问题描述】:
我正在开发一个安装了 Tailwind CSS 的 Angular 12 项目。我关注了official docs,似乎一切正常;但我不明白为什么有些课程有效而其他课程无效。
例如,我可以有这段代码,尝试在我的 div 上添加两个 Tailwind 类:
<div class=\"text-center mt-2\">
<h2>Please go back to <a class=\"custom-links\" href=\"./login\">login</a></h2>
</div>
文本中心类有效,但 mt-2 无效。这种事情正在整个项目中发生。我必须解决它的方法是使用传统的 CSS 或将其与 Tailwind 混合,如下所示:
<div id=\"back-to-login\" class=\"text-center\">
<h2>Please go back to <a class=\"custom-links\" href=\"./login\">login</a></h2>
</div>
在 CSS 上:
#back-to-login{
margin-top: 40px;
}
然后它工作正常并应用了margin-top。
你知道会发生什么吗?
像建议的here 那样重新安装 node_modules 并不能解决它。
非常感谢。
我添加了 styles.css 和 tailwind.config 的代码
样式.css
/* You can add global styles to this file, and also import other style files */
@tailwind base;
@tailwind components;
@tailwind utilities;
@font-face {
font-family: \"firechat\";
src: url(./assets/fonts/blazed/Blazed.ttf);
}
/*
to change the default h1 styles on tailwind
https://tailwindcss.com/docs/preflight#extending-preflight
*/
@layer base {
h1 {
@apply text-6xl;
}
}
/*tailwind and own styles*/
#firechat-font{
font-family: \"firechat\";
color:red;
}
.custom-links{
color:red;
font-weight: bold;
}
顺风配置文件:
module.exports = {
content: [
\"./src/**/*.{html,ts}\"
],
theme: {
extend: {},
},
plugins: [],
}
编辑:我现在看到的是,例如 mt-2 应用并出现在 devTools 上(也许问题是需要注意的微小变化,我的错),但是像 mt-4 或 mt-6 这样的较大边距不会.它也发生在其他属性上。
-
分享 style.scss 你添加了 tailwind 和 tailwind 配置文件的地方
-
@zainhassan 谢谢,完成了。它没有添加到任何 scss 文件中,而是添加到项目的全局 style.css 中。
-
你能看到
mt-2在 devTools 中应用于你的 div 吗? -
这很奇怪,但是您似乎已经使用 angular12 安装了最新版本的顺风,也许它有问题?是否可以安装tailwind v2并快速检查它是否有效。
-
@FranP 发布了我的答案。很高兴它有帮助
标签: css angular tailwind-css