{"id":1358,"date":"2023-05-02T09:54:38","date_gmt":"2023-05-02T06:54:38","guid":{"rendered":"https:\/\/notes.profidev.online\/?p=1358"},"modified":"2023-05-02T10:03:05","modified_gmt":"2023-05-02T07:03:05","slug":"light-dark-toggle","status":"publish","type":"post","link":"https:\/\/notes.profidev.online\/ru\/effect\/1358\/","title":{"rendered":"Light\/Dark Toggle"},"content":{"rendered":"<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1143\" height=\"602\" src=\"https:\/\/notes.profidev.online\/wp-content\/uploads\/2023\/05\/peek-2023-05-01-11-00.gif\" alt=\"Light\/Dark Toggle\" class=\"wp-image-1359\"\/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">  &lt;label for=&quot;theme&quot; class=&quot;theme&quot;&gt;\n    &lt;span&gt;Light&lt;\/span&gt;\n    &lt;span class=&quot;theme__toggle-wrap&quot;&gt;\n      &lt;input id=&quot;theme&quot; class=&quot;theme__toggle&quot; type=&quot;checkbox&quot; role=&quot;switch&quot; name=&quot;theme&quot; value=&quot;dark&quot;&gt;\n      &lt;span class=&quot;theme__fill&quot;&gt;&lt;\/span&gt;\n      &lt;span class=&quot;theme__icon&quot;&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n        &lt;span class=&quot;theme__icon-part&quot;&gt;&lt;\/span&gt;\n      &lt;\/span&gt;\n    &lt;\/span&gt;\n    &lt;span&gt;Dark&lt;\/span&gt;\n  &lt;\/label&gt;<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/css&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;CSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;css&quot;}\">* {\n\tborder: 0;\n\tbox-sizing: border-box;\n\tmargin: 0;\n\tpadding: 0;\n}\n:root {\n\t--hue: 223;\n\t--bg: hsl(var(--hue),10%,100%);\n\t--fg: hsl(var(--hue),10%,0%);\n\t--primary: hsl(var(--hue),90%,55%);\n\t--primaryT: hsla(var(--hue),90%,55%,0);\n\t--transDur: 0.3s;\n\tfont-size: calc(16px + (32 - 16) * (100vw - 320px) \/ (1280 - 320));\n}\nhtml,\nbody {\n\tbackground-color: var(--bg);\n}\nbody,\ninput {\n\tfont: 1em\/1.5 Fredoka, sans-serif;\n}\nbody {\n\tcolor: var(--fg);\n\theight: 100vh;\n\tdisplay: grid;\n\tplace-items: center;\n}\n\n\/* Default *\/\n.theme {\n\tdisplay: flex;\n\talign-items: center;\n\t-webkit-tap-highlight-color: transparent;\n}\n.theme__fill,\n.theme__icon {\n\ttransition: transform var(--transDur) ease-in-out;\n}\n.theme__fill {\n\tbackground-color: var(--bg);\n\tdisplay: block;\n\tmix-blend-mode: difference;\n\tposition: fixed;\n\tinset: 0;\n\theight: 100%;\n\ttransform: translateX(-100%);\n}\n.theme__icon,\n.theme__toggle {\n\tz-index: 1;\n}\n.theme__icon,\n.theme__icon-part {\n\tposition: absolute;\n}\n.theme__icon {\n\tdisplay: block;\n\ttop: 0.75em;\n\tleft: 0.75em;\n\twidth: 1.5em;\n\theight: 1.5em;\n}\n.theme__icon-part {\n\tborder-radius: 50%;\n\tbox-shadow: 0.4em -0.4em 0 0.5em hsl(0,0%,100%) inset;\n\ttop: calc(50% - 0.5em);\n\tleft: calc(50% - 0.5em);\n\twidth: 1em;\n\theight: 1em;\n\ttransition:\n\t\tbox-shadow var(--transDur) ease-in-out,\n\t\topacity var(--transDur) ease-in-out,\n\t\ttransform var(--transDur) ease-in-out;\n\ttransform: scale(0.5);\n}\n.theme__icon-part ~ .theme__icon-part {\n\tbackground-color: hsl(0,0%,100%);\n\tborder-radius: 0.05em;\n\tbox-shadow: none;\n\ttop: 50%;\n\tleft: calc(50% - 0.05em);\n\ttransform: rotate(0deg) translateY(0.5em);\n\ttransform-origin: 50% 0;\n\twidth: 0.1em;\n\theight: 0.2em;\n}\n.theme__icon-part:nth-child(3) {\n\ttransform: rotate(45deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(4) {\n\ttransform: rotate(90deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(5) {\n\ttransform: rotate(135deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(6) {\n\ttransform: rotate(180deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(7) {\n\ttransform: rotate(225deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(8) {\n\ttransform: rotate(270deg) translateY(0.5em);\n}\n.theme__icon-part:nth-child(9) {\n\ttransform: rotate(315deg) translateY(0.5em);\n}\n.theme__label,\n.theme__toggle,\n.theme__toggle-wrap {\n\tposition: relative;\n}\n.theme__toggle,\n.theme__toggle:before {\n\tdisplay: block;\n}\n.theme__toggle {\n\tbackground-color: hsl(48,90%,85%);\n\tborder-radius: 25% \/ 50%;\n\tbox-shadow: 0 0 0 0.125em var(--primaryT);\n\tpadding: 0.25em;\n\twidth: 6em;\n\theight: 3em;\n\t-webkit-appearance: none;\n\tappearance: none;\n\ttransition:\n\t\tbackground-color var(--transDur) ease-in-out,\n\t\tbox-shadow 0.15s ease-in-out,\n\t\ttransform var(--transDur) ease-in-out;\n}\n.theme__toggle:before {\n\tbackground-color: hsl(48,90%,55%);\n\tborder-radius: 50%;\n\tcontent: &quot;&quot;;\n\twidth: 2.5em;\n\theight: 2.5em;\n\ttransition:\n\t\tbackground-color var(--transDur) ease-in-out,\n\t\ttransform var(--transDur) ease-in-out;\n}\n.theme__toggle:focus {\n\tbox-shadow: 0 0 0 0.125em var(--primary);\n\toutline: transparent;\n}\n\n\/* Checked *\/\n.theme__toggle:checked {\n\tbackground-color: hsl(198,90%,15%);\n}\n.theme__toggle:checked:before,\n.theme__toggle:checked ~ .theme__icon {\n\ttransform: translateX(3em);\n}\n.theme__toggle:checked:before {\n\tbackground-color: hsl(198,90%,55%);\n}\n.theme__toggle:checked ~ .theme__fill {\n\ttransform: translateX(0);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(1) {\n\tbox-shadow: 0.2em -0.2em 0 0.2em hsl(0,0%,100%) inset;\n\ttransform: scale(1);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part ~ .theme__icon-part {\n\topacity: 0;\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(2) {\n\ttransform: rotate(45deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(3) {\n\ttransform: rotate(90deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(4) {\n\ttransform: rotate(135deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(5) {\n\ttransform: rotate(180deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(6) {\n\ttransform: rotate(225deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(7) {\n\ttransform: rotate(270deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(8) {\n\ttransform: rotate(315deg) translateY(0.8em);\n}\n.theme__toggle:checked ~ .theme__icon .theme__icon-part:nth-child(9) {\n\ttransform: rotate(360deg) translateY(0.8em);\n}\n.theme__toggle-wrap {\n\tmargin: 0 0.75em;\n}\n\n@supports selector(:focus-visible) {\n\t.theme__toggle:focus {\n\t\tbox-shadow: 0 0 0 0.125em var(--primaryT);\n\t}\n\t.theme__toggle:focus-visible {\n\t\tbox-shadow: 0 0 0 0.125em var(--primary);\n\t}\n}<\/pre><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1359,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[16],"class_list":["post-1358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-effect","tag-htmlcss"],"_links":{"self":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/comments?post=1358"}],"version-history":[{"count":9,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1358\/revisions"}],"predecessor-version":[{"id":1374,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/1358\/revisions\/1374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media\/1359"}],"wp:attachment":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media?parent=1358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/categories?post=1358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/tags?post=1358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}