Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Tailwind's group-hover is not working for me. I'm simply trying to change text color, which doesn't require any special config.

Am I forgetting something?

For reference my project is a Vue (Nuxt.js) app, all other Tailwind features are working for me and I've used TW group-hover on other projects without issue.

FAILS: Tried the following on a basic welcome page in my app.

<div class="group">
    <div class="group-hover:text-gray-300">Hover me</div>
    <div class="group-hover:text-red-300">Hover me</div>
</div>

WORKS: The same code works fine in Codepen https://codepen.io/MarsAndBack/pen/MWjroVZ

My tailwind.config.js:

module.exports = {
  variants: {},
  plugins: [
    require('@tailwindcss/custom-forms')
  ],
  purge: {
    enabled: process.env.NODE_ENV === 'production',
    content: [
      'components/**/*.vue',
      'layouts/**/*.vue',
      'pages/**/*.vue',
      'plugins/**/*.js',
      'nuxt.config.js'
    ]
  },
  theme: {
    extend: {
      colors: {
        brandGreen: {
          light: '#5bb751',
          default: '#5bb751',
          dark: '#3b7935',
          darker: '#33602e'
        }

      }
    },
    screens: {
        'xs': '480px'
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
810 views
Welcome To Ask or Share your Answers For Others

1 Answer

Found a fix, but I don't understand it.

I had to explicitly define the group-hover variant for text color, even though text color is a basic property that should work by default without having to do this, as per the TW docs.

For other basic TW projects I never had to do this. My Codepen example works without any special config. Maybe the config is required for my context of Nuxt+TW? I also tested the original issue with PurgeCSS disabled and that had no effect.

Solution:

In tailwind.config.js, explicitly define a group-hover variant for textColor, even though it's supposed work without this (for basic properties like text color):

module.exports = {

  // ...

  variants: {
    textColor: ['group-hover'],
  }

  // ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...