A theme button on a website?
-
How to implement a button on the site that, when clicked, you can change the site theme from dark to white.
A detailed description is possibleJavaScript Benjamin Wright, Aug 21, 2020 -
the easiest way is filter: invert (& lt; value & gt;);
Well, in general here many examplesAnonymous -
1.tag html add the parameter data-theme
2. in styles, set colors through variables in : root
:root[data-theme="mytheme"] {
--color-primary: $fff;
--color-secondary: $000;
--color-accent: $0f0;
...
}
3. Change the value for data-theme via JSAnonymous -
You have 2 color schemes in different files.
white.css
black.css
main.css
White.css is loaded by default
The user clicks a button, js sets a checkbox in cookies or locastoredzh that it is necessary to load black.css and either on the fly or on reboot another theme is loaded (via link in the markup head)Harper Harper
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!