3

Does tailwind allow the dark variant to work with custom classes?

Consider this simple working example:

<div class="bg-white dark:bg-black">
    Hello, world
</div>

The above will apply a black background to the element, but if try to use a custom class, then it won't:

.card-background {
    @apply bg-black;
}
<div class="bg-white dark:card-background">
    Hello, world
</div>

2 Answers 2

6

You have two way,

  • if you want to work just with colors, you can insert your colors into tailwind config file

  • if not you must define the dark class for every custom classes that you need.

for example

 .dark {
   .dark\:card-background {
     @apply bg-black;
   }
 }
Sign up to request clarification or add additional context in comments.

Comments

0

There is a problem with cssModules, and especially with css-loader.

Solution described here https://github.com/tailwindlabs/tailwindcss/issues/3258#issuecomment-753584532

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.