[CSS3] Use media query to split css files and Dark mode (prefers-color-scheme: dark)

时间:2019-12-02 20:25:28   收藏:0   阅读:114

Dark Mode:

:root {
   --text-color: #000;
   --background-color: #fff;
}
body {
  color: var(--text-color);
  background-color: var(--background-color)
}

@media (prefers-color-scheme: dark) {
    :root {
         --text-color: #fff;
         --background-color: #000; 
    }
}

 

 

If our application has multi themes, we don‘t need to iclude all the code in the init downlading.

技术分享图片

 

If there is no dark mode enabled for the site, we can force the light mode to be loaded:

技术分享图片

 

Dark mode by web component:

https://www.webcomponents.org/element/dark-mode-toggle

原文:https://www.cnblogs.com/Answer1215/p/11972750.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!