Last active
August 11, 2021 07:43
-
-
Save BlackIQ/4b89b0867964957099db9cf2309f40c5 to your computer and use it in GitHub Desktop.
Auto Dark and Light mode
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
<html> | |
<head> | |
<title>Theme</title> | |
<style> | |
/* | |
In css we have @media | |
Well, @media has many stuff but now we are going to talk about how to make an auto theme. | |
I mean if user change the browser theme, your site theme will change too. | |
In this case we use { prefers-color-scheme }. | |
*/ | |
/* Lets define things that are both same in both themes */ | |
.main { | |
padding: 5%; | |
} | |
/* Ok now we just add light theem */ | |
@media (prefers-color-scheme: light) { | |
/* Now we will describe classes */ | |
body { | |
background: white; | |
} | |
.headings { | |
color: purple; | |
} | |
.text { | |
color: blue; | |
} | |
} | |
/* Ok, we set light, time to create dark too */ | |
@media (prefers-color-scheme: dark) { | |
/* Now we will describe classes */ | |
body { | |
background: #313131; | |
} | |
.headings { | |
color: yellow; | |
} | |
.text { | |
color: red; | |
} | |
} | |
/* | |
Thanks for reading. | |
If you enjoyed, give me a star. | |
*/ | |
</style> | |
</head> | |
<body class="main"> | |
<h1 class="headings"></h1> | |
<hr> | |
<p class="text">Simple Test!</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment