This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const button = document.querySelector(".color-switch"); | |
button.addEventListener("click", function() { | |
const body = document.querySelector("body"); | |
body.classList.toggle("lightmode"); | |
body.classList.toggle("darkmode"); | |
if (button) { | |
button.innerText = body.classList.contains("lightmode") ? "Dark" : "Light"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const button: HTMLButtonElement = document.querySelector(".color-switch"); | |
button.addEventListener("click", function() { | |
const body: HTMLBodyElement = document.querySelector("body"); | |
body.classList.toggle("lightmode"); | |
body.classList.toggle("darkmode"); | |
if (button) { | |
button.innerText = body.classList.contains("lightmode") ? "Dark" : "Light"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body class="darkmode"> | |
<header> | |
<button class="color-switch">Light</button> | |
</header> | |
<h1>CSS Variable Dark Mode Switcher</h1> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-size: 1.2rem; | |
background: var(-background-fallback); | |
background: var(-background-gradient-webkit); | |
background: var(-background-gradient); | |
color: var(-text); | |
} | |
a { | |
color: var(-links-dark); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.darkmode { | |
--text: #fff; | |
--links: #66e387; | |
--bg-start: #2c5364; | |
--bg-middle: #203a43; | |
--bg-end: #0f2027; | |
--background-fallback: #0f2027; /* fallback for old browsers */ | |
--background-gradient-webkit: -webkit-linear-gradient( | |
to bottom, | |
var(--bg-start), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelector('.wrapper').style.setProperty("--textcolor","pink"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.documentElement.style.setProperty("--textcolor","pink"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.wrapper { | |
--textcolor: #66e387; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--textcolor: #ffc845; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--textcolor: #ffc845; | |
} | |
div { | |
color: var(--textcolor); | |
} | |
.wrapper { | |
--textcolor: #66e387; | |
} |
NewerOlder