简体   繁体   English

Tailwindcss 版本 3 类不适用于 class 属性,但适用于 @apply for Angular 13

[英]Tailwindcss version 3 classes not working on class attributes, but works on @apply for Angular 13

I'm unable to get Tailwindcss classes to appear on the inline "class" attribute.我无法让 Tailwindcss 类出现在内联“类”属性上。 But if I @apply I through the ".scss" file and use that class on the inline "class" attribute it works fine.但是,如果我通过“.scss”文件@apply 并在内联“类”属性上使用该 class,它就可以正常工作。

Does not work:不起作用:

.HTML .HTML

<!-- Tailwindcss NOT working -->
<div class="bg-red-500">
    <h1 class="text-9xl">HELLO</h1>
</div>

Work: .scss作品:.scss

.bg {
     @apply bg-green-500;
   }

.text {
      @apply text-9xl text-red-500;
    }

.HTML .HTML

<!-- Tailwindcss working -->
    <div class="bg-red-500">
        <h1 class="text-9xl">HELLO</h1>
    </div>

Am I missing something?我错过了什么吗? Appreciate the help in advance!提前感谢帮助!

Thanks!谢谢!

That's it right there.就在那里。 Make sure the content is correct in your tailwind config file.确保 tailwind 配置文件中的content正确。 When I updated this, turns out a new folder I created wasn't included in the config so tailwind couldn't read it.当我更新这个时,发现我创建的一个新文件夹没有包含在配置中,所以 tailwind 无法读取它。

There are a few things you need to try here:您需要在这里尝试一些事情:

Firstly, make sure that your content settings are correct in your config file:首先,确保您的配置文件中的内容设置正确:

// tailwind.config.js

module.exports = {
  content: ["./src/**/*.{html}"], //configure this line as you see fit
  theme: {
    extend: {},
  },
  plugins: [],
}

Double-check that the aforementioned line is content , not purge仔细检查上述行是否为content ,而不是purge

If that's set up correctly, let's make sure you are properly importing tailwind.如果设置正确,请确保您正确导入了顺风。 In your CSS file, add these rules to the top, and make sure that the CSS file is being properly:在您的 CSS 文件中,将这些规则添加到顶部,并确保 CSS 文件正确:

/* .src/styles.css */

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

You must be configure your template paths, add the paths to all of your template files in your tailwind.config.js file.您必须配置模板路径,将路径添加到您的tailwind.config.js文件中的所有模板文件。

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

You can learn how to connect angular and tailwind css with the link below:您可以通过以下链接了解如何连接 angular 和 tailwind css:

https://tailwindcss.com/docs/guides/angular https://tailwindcss.com/docs/guides/angular

Using Angular materials typography will override your Tailwind CSS style, so remove using the material typography and check your it will run fine.使用 Angular 材料排版将覆盖您的 Tailwind CSS 样式,因此请删除使用材料排版并检查您是否可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM