question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dark mode background color not applying when `body` styles are extracted using @apply

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adamwathancommented, Mar 17, 2021

@david-buck For what it’s worth using the code you provided, I get the expected output:

image

I also cloned down the latest version of your existing reproduction and after fixing the typo in tailwind.conifg.js to tailwind.config.js I get the expected behavior:

https://user-images.githubusercontent.com/4323180/111535037-07e3ef80-873f-11eb-9739-02fe1dbd1cb6.mov

1reaction
adamwathancommented, Mar 16, 2021

You have no darkMode setting in your config file. Set that to “media” or “class” and you should be good to go.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found