Tailwind 深色模式不适用于前缀,为什么?

Mou*_*ker 1 prefix tailwind-css darkmode

在我使用前缀之前,我可以正常使用暗模式,但是在我的顺风类中添加前缀后,我不能再使用暗模式了,有人知道如何使用前缀切换暗模式吗?

dev*_*rav 5

Your prefix needs be there in the dark mode class as well. the below example assumes you have tw as configured prefix

<!-- add your prefix here too -->
<html class="tw-dark">
<body>
  <!-- apply dark mode class with prefix -->
  <div class="bg-white dark:tw-bg-black">
    <!-- ... -->
  </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

if you don't want the prefix for the dark class then tweak the config:-

/** tailwind.config.js */
prefix: 'tw-',
darkMode: ['class', '[class="dark"]',
...
Run Code Online (Sandbox Code Playgroud)

this will allow you to switch to dark mode without adding the prefix

<!-- now no need to prefix tw-dark -->
<html class="dark">
</html>
Run Code Online (Sandbox Code Playgroud)