Last active
August 28, 2024 15:04
-
-
Save gbirke/dbdbf9570c9f62a820b8f2fe33eaf5cc to your computer and use it in GitHub Desktop.
CSS Theming experiment
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title></title> | |
<link href="style.css" rel="stylesheet"> | |
</head> | |
<body> | |
<main> | |
<div class="contrast-element"> | |
<h1> Sample text with contrast background</h1> | |
</div> | |
<div> | |
<a href="javascript:document.body.className='dark'">Dark mode</a><br> | |
<a href="javascript:document.body.className='light'">Light mode</a><br> | |
<a href="javascript:document.body.className=''">No mode</a> | |
</div> | |
</main> | |
</body> | |
</html> |
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, body.light { | |
--color-primary: #333; | |
--color-secondary: #f0f0f0; | |
--color-links: #00f; | |
} | |
body.dark { | |
--color-primary: #f0f0f0; | |
--color-secondary: #333; | |
--color-links: #0ff; | |
} | |
/* For Browser/OS configured color preferences */ | |
@media (prefers-color-scheme: light) { | |
body { | |
--color-primary: #333; | |
--color-secondary: #f0f0f0; | |
--color-links: #00f; | |
} | |
} | |
@media (prefers-color-scheme: dark) { | |
body { | |
--color-primary: #f0f0f0; | |
--color-secondary: #333; | |
--color-links: #0ff; | |
} | |
} | |
/* Common styles, no color definitions withouth variables beyone this point */ | |
body { | |
background-color: var(--color-secondary); | |
color: var(--color-primary); | |
} | |
a { | |
color: var(--color-links); | |
} | |
div { | |
margin: 10px; | |
} | |
.contrast-element { | |
border: solid 2px hwb(from var(--color-primary) h w calc( b - 10 )); | |
border-radius: 5px; | |
padding: 10px; | |
color: var(--color-secondary); | |
background-color: var(--color-primary); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment