light-dark () isn't always the same as prefers-color-scheme

摘要

light-dark() CSS函数虽能简化暗黑模式样式设置,但需搭配color-scheme: light dark;使用,否则无效。与prefers-color-scheme不同,light-dark()依赖于color-scheme值,而非操作系统设置。实现主题切换时,light-dark()表现符合预期,但prefers-color-scheme始终跟随系统设置,不受color-scheme影响。两者行为差异可能是为了保持向后兼容性。

欢迎在评论区写下你对这篇文章的看法。

评论

Home - Wiki
Copyright © 2011-2025 iteam. Current version is 2.148.1. UTC+08:00, 2025-11-29 13:03
浙ICP备14020137号-1 $Map of visitor$