A Pen by John Riggles on CodePen.
Last active
November 16, 2021 16:31
-
-
Save w3tweaks/eb01af9ab60e5ab0c19d9e06a3e95bc4 to your computer and use it in GitHub Desktop.
Dark Mode Toggle
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.toggle [type="checkbox"] | |
.bg | |
main | |
h3.heading Heading Text | |
hr | |
p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | |
p Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
h3.heading Heading Text, too | |
hr | |
p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | |
p At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis | |
p consequatur aut perferendis doloribus asperiores repellat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
h3.heading Heading Text, also! | |
hr | |
p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
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
// NOT TODAY, FOLKS! |
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
// Imports & Mixins | |
@import url('https://fonts.googleapis.com/css?family=Share'); | |
@import url('https://fonts.googleapis.com/css?family=Open+Sans'); | |
//@import url('https://rsms.me/inter/inter-ui.css'); | |
// breakpoints | |
@mixin for-size($viewport-size) { | |
@if $viewport-size == phone-only { | |
@media (max-width: 599px) { @content; } | |
} | |
@else if $viewport-size == tablet-portrait-up { | |
@media (min-width: 600px) { @content; } | |
} | |
@else if $viewport-size == tablet-landscape-up { | |
@media (min-width: 900px) { @content; } | |
} | |
@else if $viewport-size == desktop-up { | |
@media (min-width: 1200px) { @content; } | |
} | |
@else if $viewport-size == big-desktop-up { | |
@media (min-width: 1800px) { @content; } | |
} | |
} | |
// SASS Variables | |
$dark: #111; | |
$light: #EEE; | |
$toggle-height: 20px; | |
$toggle-width: $toggle-height * 2.33; | |
$border-width: 2px; | |
$header-font: "Share", sans-serif; | |
$body-font: "Open Sans", sans-serif; | |
*, *::before, *::after { | |
box-sizing: border-box; | |
} | |
html, body { | |
height: 100%; | |
width: 100%; | |
} | |
body { | |
background-color: $light; | |
font-family: $body-font; | |
font-size: 16px; | |
overflow: auto; | |
} | |
main { | |
position: absolute; | |
@include for-size(phone-only) { // vw<=599px | |
left: 10%; | |
width: 80%; | |
} | |
@include for-size(tablet-portrait-up) { // 600<=vw<=899 | |
left: 14%; | |
width: 72%; | |
} | |
@include for-size(tablet-landscape-up) { // 900<=vw<=1199 | |
left: 17%; | |
width: 66%; | |
} | |
@include for-size(desktop-up) { // 1200<=vw<=1799 | |
left: 20%; | |
width: 60%; | |
} | |
@include for-size(big-desktop-up) { // vw>=1800 (yuge!) | |
left: 24%; | |
width: 52%; | |
} | |
} | |
hr { | |
background-color: #999; | |
border: 0; | |
height: 1px; | |
} | |
.heading { | |
color: $dark; | |
font-family: $header-font; | |
font-size: 24px; | |
font-weight: 600; | |
letter-spacing: 0.05em; | |
margin-bottom: 0; | |
&:not(:first-of-type) { | |
margin-top: 2em; | |
} | |
} | |
p { | |
color: lighten($dark, 20%); | |
hyphens: auto; | |
letter-spacing: 0.02em; | |
line-height: 1.33em; | |
margin-bottom: 1em; | |
position: relative; | |
left: 1em; | |
text-align: justify; | |
width: 95%; | |
&:first-letter { | |
font-size: 24px; | |
font-weight: 600; | |
text-transform: uppercase; | |
} | |
} | |
.bg { | |
color: $dark; | |
background-color: $light; | |
height: 100%; | |
width: 100%; | |
position: fixed; | |
top: 0; | |
left: 0; | |
transition: 0.25s all linear; | |
z-index: -42; | |
} | |
.toggle { | |
cursor: pointer; | |
visibility: hidden; | |
height: $toggle-height; | |
width: $toggle-width; | |
position: fixed; | |
top: $toggle-height; | |
right: $toggle-height; | |
z-index: 2; | |
&::before, &::after { // track, slider | |
content: ""; | |
display: block; | |
transition: 0.1s all ease-in-out; | |
visibility: visible; | |
} | |
&::before { // track | |
background: $light; | |
border: $border-width solid $dark; | |
border-radius: $toggle-height; | |
height: inherit; | |
width: inherit; | |
} | |
&::after { // slider | |
background: $dark; | |
border-radius: $toggle-height - ($border-width * 4); | |
height: $toggle-height - ($border-width * 4); | |
width: $toggle-height; | |
position: absolute; | |
top: $border-width * 2; | |
left: $border-width * 2; | |
} | |
&:checked { // toggle state: checked | |
~ main .heading, ~ main p { | |
color: $light; | |
} | |
&::before { //track | |
background: $dark; | |
border: $border-width solid $light; | |
} | |
&::after { // slider | |
background: $light; | |
left: $toggle-width - $toggle-height - $border-width * 2; | |
} | |
~ .bg { | |
background: $dark; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment