color-scheme 主題顏色

使用 color-scheme 屬性只有 4個(gè)

color-scheme: normal;
color-scheme: light;
color-scheme: dark;
color-scheme: light dark; // 跟隨系統(tǒng)切換

例子: 兩套主題,class一套。 data-theme 一套,兩個(gè)都可以單獨(dú)切換單獨(dú)使用

<html lang="en" class="light" data-theme="light">
<style>
// : root 是默認(rèn)的主題顏色
:root {
    --text-1: #000;
    --text-2:#1C75B9;
    --text-link: #2483ff;
    --bg-box: rgb(200,200,200);
}
[data-theme="light"] {
    --up: #F6465D;
    --down: #CF304C;
}
[data-theme="dark"] {
    --up: #CF304C;
    --down: #F6465D;
}
.light {
  --bg-button: #2483ff;
}
.dark {
  --bg-button: #186ddd;
}
html.light{
    color-scheme: light;
}
html.dark{
    color-scheme: light;
}
</style>
</html>

使用js切換主題顏色



// class的主題
document.documentElement.setAttribute("class", "dark");

// data-theme的主題 
document.documentElement.setAttribute('data-theme', 'dark')

// 當(dāng)然也可以根據(jù)本地緩存來(lái)修改默認(rèn)值 如 
if (localStorage.getItem('upDownColor') === 'dark') {
  document.documentElement.setAttribute('data-theme', 'dark');
}

黑白之下紅綠交替

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容