Dark mode CSS in a seperate file #2947
Replies: 1 comment
-
I was about to start a similar discussion. From the heading I thought this one was about something different. I want to share a different approach to this problem. There could be a new class: But this makes it necessary to output all styles twice like this: body.dark .dark\:bg-gray-700 {
background-color: #3F3F46;
}
@media (prefers-color-scheme: dark) {
body.dark-auto .dark\:bg-gray-700 {
background-color: #3F3F46;
}
} This could also make the That way a theme switcher could cycle through |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I have a pretty simple website and I want to have light/dark mode on it. The
problem is that there are only 2 ways to do it which are not ideal.
darkMode: 'media'
It works by checking if
prefers-color-scheme
is dark, but there isn't agood way to make a JavaScript switch to change theme.
darkMode: 'class'
It works by applying dark theme if
html
hasdark
class, but there isn'ta (good) way to set it without using JavaScript.
This means that using current methods we can't have a website with working
prefers-color-scheme
without JavaScript and an additional button to switchthemes when JavaScript is enabled at the same time.
It is possible to do though,
dark:
classes would just have to be placed in aseperate file by using something like
@tailwind base-dark
. Here is a quick,messy example of how it could work (there are much better ways :L):
main.css
:dark.css
:index.html
:applytheme.js
:main.js
:Beta Was this translation helpful? Give feedback.
All reactions