简体   繁体   English

悬停时顺风文本颜色不会改变

[英]Tailwind text color not changing on hover

I'm trying to get the text color in a button to change when I hover over it but it doesn't work... My React code is this当我将鼠标悬停在按钮上时,我试图让按钮中的文本颜色发生变化,但它不起作用......我的 React 代码是这样的

 <button className="px-4 py-2 bg-blue-500 text-light hover:bg-light hover:border-2 hover:border-blue-500 hover:text-blue-500">Sign Up</button>

and my tailwind config file looks like this我的顺风配置文件看起来像这样

 const colors = require("tailwindcss/colors"); module.exports = { purge: [], darkMode: false, // or 'media' or 'class' theme: { extend: { colors: { light: "#e2f3f5", teal: "#22d1ee", blue: "#3d5af1", dark: "#0e153a", }, }, }, variants: { extend: { fontSize: ["hover", "focus"], backgroundOpacity: ["active"], borderWidth: ["hover", "focus"], textColor: [ "responsive", "dark", "group-hover", "focus-within", "hover", "focus", ], }, }, plugins: [], };

Yet the text color does not change on hover.然而,文本颜色在悬停时不会改变。 Can someone please help me?有人可以帮帮我吗?

Your issue is that you're attempting to extend Tailwind's base theme and one of your custom colors is called blue.您的问题是您正在尝试扩展 Tailwind 的基本主题,并且您的自定义颜色之一称为蓝色。 By doing this you have made bg-blue-500 not exist.通过这样做,您使bg-blue-500不存在。 If you want to extend blue you can add shades as explained here https://tailwindcss.com/docs/customizing-colors#extending-the-defaults but by doing this you have replaced blue instead of extending it.如果您想扩展蓝色,您可以按照此处的说明添加阴影https://tailwindcss.com/docs/customizing-colors#extending-the-defaults但通过这样做,您已经替换了蓝色而不是扩展它。

Once you remove that everything should work and you don't even need to have all those extended variants for textColor in your config.一旦你删除了一切都应该工作,你甚至不需要在你的配置中包含 textColor 的所有这些扩展变体。

Here it is working on Tailwind Play https://play.tailwindcss.com/7CUThekLY1?file=config这里正在处理 Tailwind Play https://play.tai​​lwindcss.com/7CUThekLY1?file=config

However, if what you really wanted was to have a class like bg-blue alongside your other bg-blue-[xxx] classes then you need to extend blue and add a key for DEFAULT like this:但是,如果您真正想要的是在其他bg-blue-[xxx]类旁边有一个像bg-blue这样的类,那么您需要扩展 blue 并为DEFAULT添加一个键,如下所示:

...
theme: {
        extend: {
            colors: {
                light: "#e2f3f5",
                teal: "#22d1ee",
                dark: "#0e153a",
                blue: {
                  'DEFAULT': '#f00'
                }
            },
        },
    },
...

Here's an example where I made bg-blue red for demonstration.这是一个示例,我将bg-blue红色以进行演示。 https://play.tailwindcss.com/VYDBylQOPu https://play.tai​​lwindcss.com/VYDBylQOPu

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

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