From 2afb2fe88ae517c00dc6aa308ad88daeb63aaabd Mon Sep 17 00:00:00 2001 From: Daihua Ye Date: Tue, 2 Oct 2018 22:55:20 -0700 Subject: [PATCH] Add a new snippet: CSS toggle switch (#98) * Add snippet for visual, interactivity: CSS toggle switch * Add Explanation #8 * add transition for button and change background color from blue to #7983ff * add explanation #9 * address based on comment. * update the css matched with explanation description * Remove 'CSS' from title for simplicity * Explanation grammar * class scoping * Explanation improvements --- snippets/toggle-switch.md | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 snippets/toggle-switch.md diff --git a/snippets/toggle-switch.md b/snippets/toggle-switch.md new file mode 100644 index 000000000..98961619e --- /dev/null +++ b/snippets/toggle-switch.md @@ -0,0 +1,113 @@ +### Toggle switch + +Creates a toggle switch with CSS only. + +#### HTML + +```html + + +``` + +#### CSS + +```css +.switch { + position: relative; + display: inline-block; + width: 40px; + height: 20px; + background-color: rgba(0, 0, 0, 0.25); + border-radius: 20px; + transition: all 0.3s; +} + +.switch::after { + content: ''; + position: absolute; + width: 18px; + height: 18px; + border-radius: 18px; + background-color: white; + top: 1px; + left: 1px; + transition: all 0.3s; +} + +input[type='checkbox']:checked + .switch::after { + transform: translateX(20px); +} + +input[type='checkbox']:checked + .switch { + background-color: #7983ff; +} + +.offscreen { + position: absolute; + left: -9999px; +} +``` + +#### Demo + +
+ + +
+ + + +#### Explanation + +This effect is styling only the `