简体   繁体   English

Tailwind css 悬停不会改变文本颜色

[英]Tailwind css hover not changing text color

I am completely new to this tailwindcss and I have been stuck at this problem for the entire day.我对这个 tailwindcss 完全陌生,我一整天都被这个问题困住了。 I am so frustrated.我很沮丧。 Here is my code这是我的代码

<button className="bg-yellow-500 px-4 py-2 hover:text-black text-white">
        Some Text Here
 </button>

What I want to achieve is to change the text color when the button is hovered, current text color is white and I want it to change to black.我想要实现的是在按钮悬停时更改文本颜色,当前文本颜色为白色,我希望将其更改为黑色。 It didn't work.它没有用。 When I use chrome inspect tool, I found that the text color white has !important which I don't know how it happened.当我使用 chrome 检查工具时,我发现文本颜色 white 有 !important ,我不知道它是怎么发生的。 I didn't define it, don't even know how to.我没有定义它,甚至不知道如何定义。 What's even worst is that I can change the text color to any color when it's hovered if it's original color is not white.更糟糕的是,如果它的原始颜色不是白色,我可以在悬停时将文本颜色更改为任何颜色。 I can have another color initially other than white and change it to whatever color I like.我最初可以使用白色以外的另一种颜色,然后将其更改为我喜欢的任何颜色。 As you can see, its very simple.如您所见,它非常简单。 I can do it with pure css in like 10 s, no need to for an entire day.我可以在 10 秒内用纯 css 完成,不需要一整天。 Please, help me out here.请帮帮我。

Here is the tailwind.config file if it's necessay,如果需要,这里是 tailwind.config 文件,

const colors = require("tailwindcss/colors");

module.exports = {
  purge: ["./src/**/*.{js,jsx,ts,tsx}"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    boxShadow: {
      sm: "0 1px 5px #65656599",
    },
    extend: {
      fontFamily: {
        body: ["Poppins"],
      },
      colors: {
        black: {
          hakkei: "#1a1a1a",
          DEFAULT: "#000",
        },
        current: "currentColor",
        gray: colors.blueGray,
        indigo: colors.indigo,
        red: colors.rose,
        yellow: colors.amber,
        blue: colors.blue,
        black: "#333",
        white: "#fff",
        aqua: {
          DEFAULT: "#99ced3",
          dark: "#8abbbf",
        },
        navy: {
          light: "#99ced3",
          DEFAULT: "#2f415d",
          dark: "#1d2a3d",
          sky: "#00afffc2",
        },
        purple: colors.purple,
      },
      borderRadius: {
        "5xl": "5rem",
        "10xl": "10rem",
        "20xl": "50%",
      },
      height: {
        120: "32rem",
        150: "40rem",
      },
    },
  },
  variants: {
    textColor: ["responsive", "hover", "focus", "group-hover"],
  },

  plugins: [
    "gatsby-plugin-postcss",
    //require('@tailwindcss/forms'),
    "@tailwindcss-neumorphism",
  ],
};

You have defined black twice.你已经定义了black两次。 If you want the default value for black to be #333 then just add that value like the following:如果您希望黑色的默认值为#333则只需添加该值,如下所示:

      colors: {
        black: {
          hakkei: "#1a1a1a",
          DEFAULT: "#333", // it was #000 before
        },

and remove the other line between blue and white.并删除蓝色和白色之间的另一条线。

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

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