尝试将悬停:应用于我制作的 Tailwind CSS 自定义类,但它似乎不起作用
示例:
.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案在文档中。如果有人遇到这个问题,那么它的发生是因为我在 tailwind @components 下声明了样式,而它应该是 tailwind @utilities。
然后按照您的意愿使用状态 - 例如,在这种情况下,
上面现在就可以了!
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.
And then use the states as you would - for example, in this case
Above now will work!
您只是忘记应用伪类,例如: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
您好,这是一个设置问题,请检查您的index.css 文件
Hi it's a setting problem check your index.css file