简体   繁体   English

CSS 黑暗主题媒体查询在 Firefox 和 Chrome 上不起作用?

[英]CSS Dark Theme Media Queries not working on Firefox and Chrome?

I recently switched my site to use media queries to change the site's theme from light mode to dark mode.我最近将我的网站切换为使用媒体查询将网站的主题从浅色模式更改为深色模式。

It works on the Edge browser for desktop and mobile, but doesn't work on Firefox and Chrome (desktop and mobile).它适用于台式机和移动设备的 Edge 浏览器,但不适用于 Firefox 和 Chrome(台式机和移动设备)。

Why aren't these media queries working on Firefox and Chrome, and how can I troubleshoot this issue?为什么这些媒体查询在 Firefox 和 Chrome 上不起作用,我该如何解决这个问题?

OS Windows 10 system theme is light Chrome Version 90.0.4430.212 Firefox Version Version 88.0.1 OS Windows 10 系统主题是浅色 Chrome 版本 90.0.4430.212 Firefox 版本 88.0.1

 body { /* Black-on-white by default */ background: #fff; color: #000; } @media (prefers-color-scheme: dark) { /* White-on-black if user prefers dark color scheme */ body { background: #000; color: #fff; } }
 <p>Hello, StackOverflow!</p>

Chrome and Firefox also look at the theme preference of your operating system. Chrome 和 Firefox 还会查看您操作系统的主题偏好。

If you are on Windows with your operating system theme set to light, even if Chrome and Firefox are dark theme, they will not load webpages in dark theme.如果您在 Windows 上将操作系统主题设置为浅色,即使 Chrome 和 Firefox 是深色主题,它们也不会加载深色主题的网页。

If you change your Windows operating system theme to dark theme, then Chrome and Firefox will change.如果您将 Windows 操作系统主题更改为深色主题,则 Chrome 和 Firefox 将更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM