Disable dark mode on certain dom element #10646
Replies: 7 comments 12 replies
-
@adamwathan Could you please check if this is possible & needed? If this API was approved I would work on this |
Beta Was this translation helpful? Give feedback.
-
Any good solutiuon for this yet? |
Beta Was this translation helpful? Give feedback.
-
Just sharing my workaround right know: plugins: [
plugin(({ addVariant }) => {
addVariant("dark", [":is(.dark &):not(.light &)"]);
})
] <div class="dark">
It's dark!
<div class="light">
It's back to light!
</div>
</div> It changes dark variant to The issue with this approach is that you cannot back to dark mode inside .light anymore. <div class="dark">
It's dark!
<div class="light">
It's back to light!
<div class="dark">
It's still light :(
</div>
</div>
</div> |
Beta Was this translation helpful? Give feedback.
-
Any update ? |
Beta Was this translation helpful? Give feedback.
-
Here are two solutions, one using arbitrary variants and one using a static variant plugin. |
Beta Was this translation helpful? Give feedback.
-
Try |
Beta Was this translation helpful? Give feedback.
-
I had a slightly different situation: instead of forcing a light mode, I wanted to invert the theme. The component should be light in dark mode and dark in light mode. Maybe someone will find my solution useful: module.exports = {
darkMode: ['variant', ':is(.dark &, .dark-invert &):not(.dark .dark-invert &)'],
// ...
} Then usage: <div class="dark-invert">
<p class="text-red-500 dark:text-blue-500">
I'm red in dark mode and blue in light mode
</p>
</div> I'd love to see other/better solutions 👀 |
Beta Was this translation helpful? Give feedback.
-
I think it would be useful to have the ability to disable dark mode on certain elements.
For example, in Tailwind docs, we can declare darkMode option as following:
Then we're enabling dark mode globally, for example:
Then use dark mode classes like:
But I faced a situation when I need to disable dark mode only in one element (by some condition). Something like this:
Is it possible to have some API that will allow to disable dark mode on some node element ? By applying
light
CSS class for example:Beta Was this translation helpful? Give feedback.
All reactions