css dark theme & js theme checker
阅读原文时间:2023年07月12日阅读:1

css dark theme & js theme checker

live demo

https://codepen.io/xgqfrms/pen/GRprYLm

<!DOCTYPE html>
<html lang="zh-Hans" ️amp>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="xgqfrms">
    <meta name="generator" content="VS code">
    <title>css dark theme</title>
    <!-- css -->
</head>
<body data-theme="css-theme-flag">
    <header>
        <h1 class="header-h1"></h1>
    </header>
    <footer>
        <p>copyright&copy; xgqfrms 2020</p>
    </footer>
    <!-- js -->
</body>
</html>


:root {
  --mode: 'unknown';
  --lightColor: #000;
  --darkColor: #fff;
  --lightBackground: #fff;
  --darkBackground: #000;
}

@media (prefers-color-scheme: light) {
  /* 浅色主题 */
  :root {
     --mode: 'light';
     --colorLink: #34538b;
     --colorMark: #cc0000;
     --colorText: #000000;
     --colorLight: #cccccc;
  }
  [data-theme="css-theme-flag"] {
    background: var(--lightBackground);
    color: var(--darkColor);
    // flag: "light";
    content: "light";
  }
}

@media (prefers-color-scheme: dark) {
  /* 暗黑模式 */
  :root {
     --mode: 'dark';
     --colorLink: #bfdbff;
     --colorMark: #cc0000;
     --colorText: #ffffff;
     --colorLight: #777777;
  }
  [data-theme="css-theme-flag"] {
    background: var(--darkBackground);
    color: var(--darkColor);
    // flag: "dark";
    content: "dark";
  }
}

pre{
  color: #0f0;
}



/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-04-23
 * @modified
 *
 * @description css dark theme & js theme checker
 * @augments
 * @example
 * @link https://www.cnblogs.com/xgqfrms/p/12764741.html
 *
 */

const log = console.log;

const body = document.querySelector(`[data-theme="css-theme-flag"]`);
const h1 = document.querySelector(`h1`);

const color = window.getComputedStyle(body, null).color;
// log(`body color`, color);

const theme = window.getComputedStyle(body, null).content;
log(`body theme`, theme);

if(theme === `"dark"`) {
  h1.innerText = `css dark theme`;
} else {
  h1.innerText = `css light theme`;
}

https://www.cnblogs.com/xgqfrms/p/10059410.html

@media (prefers-color-scheme: dark) {
  .js_darkmode__0 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__1 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__2 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__3 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__4 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__5 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__6 {
    color: rgb(167, 167, 167) !important;
  }
}



@media (prefers-color-scheme: dark) {
  .js_darkmode__7 {
    color: rgb(167, 167, 167) !important;
  }

  .js_darkmode__31 {
    background: rgb(192, 190, 183) !important;
  }

  .js_darkmode__37 {
    color: rgb(167, 167, 167) !important;
  }

}



@media (prefers-color-scheme: dark) {
body:not([data-weui-theme='light']) {
    --weui-BG-COLOR-ACTIVE: #282828;
}
}

@media (prefers-color-scheme: dark) {
body:not([data-weui-theme='light']) {
    --weui-BG-0: #191919;
    --weui-BG-1: #1f1f1f;
    --weui-BG-2: #232323;
    --weui-BG-3: #2f2f2f;
    --weui-BG-4: #606060;
    --weui-BG-5: #2c2c2c;
    --weui-FG-0: rgba(255,255,255,0.8);
    --weui-FG-HALF: rgba(255,255,255,0.6);
    --weui-FG-1: rgba(255,255,255,0.5);
    --weui-FG-2: rgba(255,255,255,0.3);
    --weui-FG-3: rgba(255,255,255,0.05);
    --weui-RED: #fa5151;
    --weui-ORANGE: #c87d2f;
    --weui-YELLOW: #cc9c00;
    --weui-GREEN: #74a800;
    --weui-LIGHTGREEN: #28b561;
    --weui-BRAND: #07c160;
    --weui-BLUE: #10aeff;
    --weui-INDIGO: #1196ff;
    --weui-PURPLE: #8183ff;
    --weui-WHITE: rgba(255,255,255,0.8);
    --weui-LINK: #7d90a9;
    --weui-TEXTGREEN: #259c5c;
    --weui-FG: white;
    --weui-BG: black;
    --weui-TAG-TEXT-ORANGE: rgba(250,157,59,0.6);
    --weui-TAG-BACKGROUND-ORANGE: rgba(250,157,59,0.1);
    --weui-TAG-TEXT-GREEN: rgba(6,174,86,0.6);
    --weui-TAG-BACKGROUND-GREEN: rgba(6,174,86,0.1);
    --weui-TAG-TEXT-BLUE: rgba(16,174,255,0.6);
    --weui-TAG-BACKGROUND-BLUE: rgba(16,174,255,0.1);
    --weui-TAG-TEXT-BLACK: rgba(255,255,255,0.5);
    --weui-TAG-BACKGROUND-BLACK: rgba(255,255,255,0.05);
}
}


xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章