跳到正文
Skillpedia
网站与界面(前端)75k · #2807

dark-mode-css

它能做什么

这项技能为网站的颜色添加深色版本。适合希望网站在夜间看起来舒适,并尊重设备设置的开发者。

适用场景

  • ✓当访客要求用深色主题在夜间阅读时。
  • ✓当网站的固定颜色在深色背景上显示不正常时。
  • ✓当你希望网站跟随每位访客设备的浅色或深色设置时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dark-mode-css/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dark-mode-css/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能为我的网站添加跟随系统设置的深色模式吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会把颜色移入具名的值中,并为深色模式设置不同的值。它还可以添加一个切换开关,让访客自行选择主题。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Support dark mode with prefers-color-scheme

More than half of users prefer dark mode for reduced eye strain, especially in low-light environments. Users with photosensitivity rely on it. Implementing dark mode via prefers-color-scheme respects the user's OS preference without them needing to find a toggle, and CSS custom properties make it a clean, maintainable addition rather than a disruptive refactor.

Quick Reference

  • Use @media (prefers-color-scheme: dark) to apply dark mode styles
  • Define light/dark colors as CSS custom properties on :root for easy switching
  • Support a manual toggle by storing preference in localStorage and setting a data-theme attribute
  • Ensure dark mode colors maintain WCAG contrast ratios

Check

Check if this CSS supports dark mode. Look for prefers-color-scheme usage or a data-theme attribute pattern. Identify any hard-coded colors that would look wrong in dark mode.

Fix

Implement dark mode by extracting colors to CSS custom properties and redefining them inside a prefers-color-scheme: dark media query.

Explain

Explain how to implement dark mode with CSS custom properties, the prefers-color-scheme media query, and a JavaScript toggle for user preference.

Code Review

Review stylesheets, component styles, and responsive states related to Support dark mode with prefers-color-scheme. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/css/dark-mode-css

常见问题

网站怎么知道访客想要深色模式?

浏览器会报告设备设置,页面据此自动选择深色配色。

访客可以自己选择主题吗?

可以。这项技能描述了一个手动切换开关,其选择会保存在浏览器中。

深色模式下文字会清晰可读吗?

这项技能说明,要保持足够高的对比度,达到文字的无障碍标准。

详情

作者的原始描述

Use when reviewing stylesheets, component styles, and responsive behavior related to Support dark mode with prefers-color-scheme. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2807
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能