Dark mode background color not applying when `body` styles are extracted using @apply
See original GitHub issueI have this in my globals.css:
body { @apply font-body antialiased max-w-xl mx-auto text-gray-900 bg-white dark:bg-gray-800 dark:text-white transition-colors; }
And it works in the old way, but with JIT, it doesn’t apply the dark:bg-gray-800
, while the dark:text-white
works fine.
The result is white text on a white background in dark mode.
Background colour changes to other elements apply fine, only body
is unaffected.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Dark mode background color not applying when `body` styles ...
The result is white text on a white background in dark mode. Background colour changes to other elements apply fine, only body is...
Read more >Why the dark-theme colors written in the SCSS file does not ...
Inside your dark mode toggle function, you need to toggle the class dark on the body element. Also, in your markup, you cannot...
Read more >Dark Mode to Change Color Schemes and CSS Properties
Developers are adding dark mode CSS on native applications to support their user preferences. Read to learn more about dark color schemes for...
Read more >How to implement dark mode with css - secretGeek.net
How to implement dark mode with css. The way I like to implement this is by combining "custom properties" with prefers-color-scheme: dark ....
Read more >prefers-color-scheme: Hello darkness, my old friend - web.dev
I have done a lot of background research on the history and theory of dark mode, if you are only interested in working...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@david-buck For what it’s worth using the code you provided, I get the expected output:
I also cloned down the latest version of your existing reproduction and after fixing the typo in
tailwind.conifg.js
totailwind.config.js
I get the expected behavior:https://user-images.githubusercontent.com/4323180/111535037-07e3ef80-873f-11eb-9739-02fe1dbd1cb6.mov
You have no
darkMode
setting in your config file. Set that to “media” or “class” and you should be good to go.