Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Tailwind dark variant with custom classes

Tags:

tailwind-css

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>
like image 858
Thiago Avatar asked May 21 '26 15:05

Thiago


1 Answers

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;
   }
 }
like image 186
Erfan HosseinPoor Avatar answered May 26 '26 23:05

Erfan HosseinPoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!