CSS
css/light-dark-color-scheme
A project that uses light-dark() declares color-scheme (light dark) on :root or in a meta tag, or the dark values never apply.
umiarkowanastatycznefe-css-modern
Dlaczego
light-dark(a, b) returns the dark value only when the element's used colour scheme is dark, and that comes from the color-scheme property (or the color-scheme meta tag). Without it the page always shows the light values, whatever the person chose in their system, and form controls and scrollbars stay light too.
Poprawka
Add color-scheme: light dark; to :root (or <meta name="color-scheme" content="light dark"> in the document head). For a forced theme toggle, set color-scheme: dark or light on the root element from the toggle.
Przykłady
/* bad */
:root { --bg: light-dark(#fff, #121212); }
/* good */
:root { color-scheme: light dark; --bg: light-dark(#fff, #121212); }Źródła
Fakty
- Identyfikator
css/light-dark-color-scheme- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
project- Uczy jej skill
fe-css-modernModern CSS features- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain css/light-dark-color-scheme