英文:
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.
<button class="event-button-secondary w-32">Deactive</button>
答案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;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论