尝试将悬停:应用于我制作的 Tailwind CSS 自定义类,但它似乎不起作用

发布于 2025-01-16 12:24:22 字数 686 浏览 2 评论 0原文

示例:

.btn {bg-blue-500 text-2 text-orange-300}
.btn2 {bg-orange-500 text-2 text-blue-300}

尝试:

编辑: 很抱歉,我忘记包含我正在使用的代码...当时是深夜。

< button className="btn hover:btn2"/>   <---this does not work btn2 does not actually get applied as a hover

btn 当然会出现,但悬停时,btn2 样式不会出现。

如果我做了一些愚蠢的事情或者我明显错过了文档中已经说明的内容,请随时为我指出方向。

我尝试过搜索,但我在兜圈子,我只是有很多样式,我想通过在不同的状态下应用它们来更改功能,但这将是一个痛苦,因为我必须创建一个单独的 .btn .btn2 btn2-hover btn-hover 等等..等等..

这是一个变体问题吗?或者它是一个按一定顺序读取 css 的过程?难道我期望将悬停应用于所有内部 css 但它实际上并没有这样做?或者我需要做出一些例外吗?我很混乱。

Example:

.btn {bg-blue-500 text-2 text-orange-300}
.btn2 {bg-orange-500 text-2 text-blue-300}

Attempted:

Edit: I'm sorry I forgot to include the code I was using... it was late night.

< button className="btn hover:btn2"/>   <---this does not work btn2 does not actually get applied as a hover

btn of course appears, but upon hovering, btn2 styling does not appear.

If i'm doing something stupid or I clearly missed something already stated in the docs, feel free to just point me in the direction.

I've tried searching but I'm going in circles and I just have a lot of styles I'd like to change functionally by applying them in different states, but its going to be a pain in I have to create a separate .btn .btn2 btn2-hover btn-hover etc.. etc..

Is it a variant issue? Or is it a process that reads the css in a certain order? Could it be that I'm expecting hover to be applied to all internal css when it really doesn't do that? Or do I need to make some exception? I'm jumbled.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷血 2025-01-23 12:24:22

答案在文档中。如果有人遇到这个问题,那么它的发生是因为我在 tailwind @components 下声明了样式,而它应该是 tailwind @utilities。

@layer utilities{
.btn {bg-blue-500 text-2 text-orange-300}
.btn2 {bg-orange-500 text-2 text-blue-300}}

然后按照您的意愿使用状态 - 例如,在这种情况下,

<button className="btn hover:btn2"/>

上面现在就可以了!

The answer was in the docs. If anyone has this problem, it occurred because I had my declared styles under tailwind @components, when it should be tailwind @utilities.

@layer utilities{
.btn {bg-blue-500 text-2 text-orange-300}
.btn2 {bg-orange-500 text-2 text-blue-300}}

And then use the states as you would - for example, in this case

<button className="btn hover:btn2"/>

Above now will work!

夏至、离别 2025-01-23 12:24:22

您只是忘记应用伪类,例如:hover

https://tailwindcss.com/docs/hover-focus-and-other-states

如果您使用的是 css,则可以使用 @apply 按照您的风格然后使用tailwindcss 类。在这种情况下,您还必须使用 :hover

You simply forgot to apply Pseudo-classes like :hover:

https://tailwindcss.com/docs/hover-focus-and-other-states

and if you're using css, you can use @apply in your style and then use tailwindcss class. In that case, you must also use :hover

ぶ宁プ宁ぶ 2025-01-23 12:24:22

您好,这是一个设置问题,请检查您的index.css 文件

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

html, body, #root{
      width: 100%;
      height: 100%;
}

Hi it's a setting problem check your index.css file

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

html, body, #root{
      width: 100%;
      height: 100%;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文