HTML class not working with custom Tailwind class.

huangapple go评论78阅读模式
英文:

Html class not working with custom Tailwind class

问题

input.css:我的自定义 CSS 文件

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

.event-button-secondary {
    height: 114px;
    max-width: 420px;
    @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text-event-text-200 hover:bg-event-text-300 hover:text-event-text-200;
}

html 页面:我在 HTML 标签中写的"w-32"不起作用。

<button class="event-button-secondary w-32">停用</button>
英文:

input.css: My custom css file

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

.event-button-secondary {
    height: 114px;
    max-width: 420px;
    @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text-event-text-200 hover:bg-event-text-300 hover:text-event-text-200;
}

html page: The "w-32" I wrote in the html tag doesn't work.

&lt;button class=&quot;event-button-secondary w-32&quot;&gt;Deactive&lt;/button&gt;

答案1

得分: 3

如果您需要使用Tailwind来编写外部CSS,则需要使用@layer components编写代码,以下是一个示例。

@layer components{ .event-button-secondary { height: 114px; max-width: 420px; @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text-event-text-200 hover:bg-event-text-300 hover:text-event-text-200; } }

英文:

if you need to right external CSS with tailwind then you need to write code with @layer components and here is an example below.

@layer components{ .event-button-secondary { height: 114px; max-width: 420px; @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text-event-text-200 hover:bg-event-text-300 hover:text-event-text-200; } }

答案2

得分: 0

我解决了。如果你写成!w-32而不是w-32,它会起作用,但在Tailwind中,我们被要求在@layer内编写这样的类,以防止这种情况发生。所以如果你像这样写它:

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

@layer components {
 .event-button-secondary {
 height: 114px;
 max-width: 420px;
 @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text-event-text-200 hover:bg-event-text-300 hover:text-event-text-200;
 }
}
英文:

I solve it. If you write !w-32 instead of w-32, it will work, but in Tailwind, we are asked to write such classes within @layer to prevent this situation. So if you write it like this:

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

@layer components {
 .event-button-secondary {
 height: 114px;
 max-width: 420px;
 @apply rounded-lg font-inter text-base-bold border-none bg-event-text-300 text- 
 event-text-200 hover:bg-event-text-300 hover:text-event-text-200;
 }
}

huangapple
  • 本文由 发表于 2023年1月8日 22:34:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定