# 深色/浅色模式切换

**URL:** https://meta.discourse.org/t/dark-light-mode-toggle/215585
**Category:** Theme component
**Tags:** deprecated, dark-mode-toggle
**Created:** [2022年一月21日 18:50 UTC](https://meta.discourse.org/t/dark-light-mode-toggle/215585 "2022-01-21T18:50:36Z")
**Posts on this page:** 1
**Showing post:** 164

<div class="post-metadata">

### Author: ![Andrew\_Rowe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrew_rowe/32/445877_2.png) [@Andrew\_Rowe](https://meta.discourse.org/u/Andrew_Rowe)
#### Post date: [2024年十二月28日 20:17 UTC](https://meta.discourse.org/t/dark-light-mode-toggle/215585/164 "2024-12-28T20:17:29Z")

</div>

感谢您的帮助  
我正在使用这个深色/浅色模式切换组件

> [@Moin](#):
>
> 您的问题是关于这个添加了切换到暗模式的切换按钮的主题组件，还是关于检测暗色调色板的一般性问题？

我的问题是关于检测我处于哪种模式，并切换背景图片，这样我就可以为浅色模式和深色模式设置不同的图片。

我尝试按照您发布的链接以及这个链接进行操作

> [@Different CSS changes for different color schemes](https://meta.discourse.org/t/different-css-changes-for-different-color-schemes/282436/4?u=andrew_rowe):
>
> If I understand the issue well, there’s a specific thing to do for this. I’ve been working on a guide about this, but I’m struggling a bit to merge information so it’s clear enough to directly use the information in a theme, but still explains underlying technical stuff. To explain how to do it the most clearly as I can… I suggest you create a theme locally (using [Install the Discourse Theme CLI console app to help you build themes](https://meta.discourse.org/t/install-the-discourse-theme-cli-console-app-to-help-you-build-themes/82950) will help). Then, create a common/color\_definitions.scss …

其中包含更详细的信息，但我没有成功。我尝试将图片文件（JPG）$bg-light 和 $bg-dark 添加到我的主题中

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/f/7/9f708100325d32e09fbf0bd8279d9d86858adfd9.png)  
我还尝试在我的主题中添加一个 color\_definitions.scss 样式表，其中包含该帖子中的代码

```plaintext
$bg: url(dark-light-choose($bg-light, $bg-dark));

:root {
  --custom-bg: #{$bg};
}

```

我还尝试在 GitHub 上创建一个主题

> **[GitHub - MyRaceData/WebsiteTheme](https://github.com/MyRaceData/WebsiteTheme)**
>
> Contribute to MyRaceData/WebsiteTheme development by creating an account on GitHub.

正如我所说，抱歉我有点迷茫  
如果我应该开一个新话题，请告诉我，并说明应该放在哪个类别  
感谢您的帮助

---

_[View the full topic](https://meta.discourse.org/t/dark-light-mode-toggle/215585)._
