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

发布于 2025-01-13 18:10:53 字数 70 浏览 6 评论 0原文

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

before I use the prefix , I could use dark mode normally , but after made a prefix to my tailwind classes , I cannot use the dark mode no longer , anyone know how to toggle dark mode with prefix ?, please

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

待天淡蓝洁白时 2025-01-20 18:10:53

您的前缀也需要出现在深色模式类中。
下面的示例假设您将 tw 作为配置的前缀,

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

如果您不需要 dark 类的前缀,则调整配置:-

/** tailwind.config.js */
prefix: 'tw-',
darkMode: ['class', '[class="dark"]',
...

这将允许您切换到 dark不添加前缀的模式

<!-- now no need to prefix tw-dark -->
<html class="dark">
</html>

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>

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

/** tailwind.config.js */
prefix: 'tw-',
darkMode: ['class', '[class="dark"]',
...

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

<!-- now no need to prefix tw-dark -->
<html class="dark">
</html>
白龙吟 2025-01-20 18:10:53

唯一对我有用的是@servetoz 响应。您应该在 tailwind.config.js 中设置 darkMode: ['class', '[class*="dark"]']

The only thing that worked for me was @servetoz response. You should set darkMode: ['class', '[class*="dark"]'] in tailwind.config.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文