Created
October 9, 2023 11:04
-
-
Save codepedia-top/8f41d28f507b7f2cdce706feb8fc6398 to your computer and use it in GitHub Desktop.
switch to dark mode and light mode
This file contains hidden or 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
| <input type="checkbox" id="toggle" class="toggle--checkbox"> | |
| <label for="toggle" class="toggle--label"> | |
| <span class="toggle--label-background"></span> | |
| </label> | |
| <div class="background"></div> |
This file contains hidden or 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 { | |
| /** sunny side **/ | |
| --blue-background: #e5e9f0; | |
| --blue-border: #81a1c1; | |
| --blue-color: #5e81ac; | |
| --yellow-background: #ebcb8b; | |
| --yellow-border: #fbcb8f; | |
| /** dark side **/ | |
| --indigo-background: #434c5e; | |
| --indigo-border: #81a1c1; | |
| --indigo-color: #5e81ac; | |
| --gray-border: #e8e8ea; | |
| --gray-dots: #e8e8ea; | |
| /** general **/ | |
| --white: #fff; | |
| } | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| } | |
| body { | |
| display: grid; | |
| place-items: center; | |
| min-height: 100vh; | |
| position: relative; | |
| } | |
| .background { | |
| position: absolute; | |
| left: 0; | |
| top: 0; | |
| background: var(--blue-background); | |
| z-index: -1; | |
| width: 100%; | |
| height: 100%; | |
| transition: all 250ms ease-in; | |
| } | |
| .toggle--checkbox { | |
| display: none; | |
| } | |
| .toggle--checkbox:checked { | |
| /** This will all flip from sun to moon **/ | |
| /** Change the label color **/ | |
| } | |
| .toggle--checkbox:checked ~ .background { | |
| background: var(--indigo-background); | |
| } | |
| .toggle--checkbox:checked + .toggle--label { | |
| background: var(--indigo-color); | |
| border-color: var(--indigo-border); | |
| /** Change the cloud to stars **/ | |
| /** Change the sun into the moon **/ | |
| /** Show the dimples on the moon **/ | |
| } | |
| .toggle--checkbox:checked + .toggle--label .toggle--label-background { | |
| left: 60px; | |
| width: 5px; | |
| } | |
| .toggle--checkbox:checked + .toggle--label .toggle--label-background:before { | |
| width: 5px; | |
| height: 5px; | |
| top: -25px; | |
| } | |
| .toggle--checkbox:checked + .toggle--label .toggle--label-background:after { | |
| width: 5px; | |
| height: 5px; | |
| left: -30px; | |
| top: 20px; | |
| } | |
| .toggle--checkbox:checked + .toggle--label:before { | |
| background: var(--white); | |
| border-color: var(--gray-border); | |
| animation-name: switch; | |
| animation-duration: 350ms; | |
| animation-fill-mode: forwards; | |
| } | |
| .toggle--checkbox:checked + .toggle--label:after { | |
| transition-delay: 350ms; | |
| opacity: 1; | |
| } | |
| .toggle--label { | |
| /** Placeholder element, starting at blue **/ | |
| width: 200px; | |
| height: 100px; | |
| background: var(--blue-color); | |
| border-radius: 100px; | |
| border: 5px solid var(--blue-border); | |
| display: flex; | |
| position: relative; | |
| transition: all 350ms ease-in; | |
| /** The sun cloud and moon stars **/ | |
| /** Sun/Moon element **/ | |
| /** Gray dots on the moon **/ | |
| } | |
| .toggle--label-background { | |
| width: 10px; | |
| height: 5px; | |
| border-radius: 5px; | |
| position: relative; | |
| background: var(--white); | |
| left: 135px; | |
| top: 45px; | |
| transition: all 150ms ease-in; | |
| } | |
| .toggle--label-background:before { | |
| content: ""; | |
| position: absolute; | |
| top: -5px; | |
| width: 40px; | |
| height: 5px; | |
| border-radius: 5px; | |
| background: var(--white); | |
| left: -20px; | |
| transition: all 150ms ease-in; | |
| } | |
| .toggle--label-background:after { | |
| content: ""; | |
| position: absolute; | |
| top: 5px; | |
| width: 40px; | |
| height: 5px; | |
| border-radius: 5px; | |
| background: var(--white); | |
| left: -10px; | |
| transition: all 150ms ease-in; | |
| } | |
| .toggle--label:before { | |
| animation-name: reverse; | |
| animation-duration: 350ms; | |
| animation-fill-mode: forwards; | |
| transition: all 350ms ease-in; | |
| content: ""; | |
| width: 82px; | |
| height: 82px; | |
| border: 5px solid var(--yellow-border); | |
| top: 4px; | |
| left: 4px; | |
| position: absolute; | |
| border-radius: 82px; | |
| background: var(--yellow-background); | |
| } | |
| .toggle--label:after { | |
| transition-delay: 0ms; | |
| transition: all 250ms ease-in; | |
| position: absolute; | |
| content: ""; | |
| box-shadow: var(--gray-dots) -13px 0 0 2px, var(--gray-dots) -24px 14px 0 -2px; | |
| left: 143px; | |
| top: 23px; | |
| width: 10px; | |
| height: 10px; | |
| background: transparent; | |
| border-radius: 50%; | |
| opacity: 0; | |
| } | |
| @keyframes switch { | |
| 0% { | |
| left: 4px; | |
| } | |
| 60% { | |
| left: 4px; | |
| width: 112px; | |
| } | |
| 100% { | |
| left: 104px; | |
| width: 82px; | |
| } | |
| } | |
| @keyframes reverse { | |
| 0% { | |
| left: 104px; | |
| width: 82px; | |
| } | |
| 60% { | |
| left: 72px; | |
| width: 112px; | |
| } | |
| 100% { | |
| left: 4px; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment