Pure CSS light switch
How do I make an pure css light switch?
Inspired by Mike Ackerman's work on Dribbble : http://dribbble.com/shots/337902-Light-Switches. Except for the right shadow on the initial state, it was pretty easy to do. I even felt confident enough to change some shadows from the original work.. What is a pure css light switch? How do you make a pure css light switch? This script and codes were developed by Hugo Giraudel on 09 August 2022, Tuesday.
Pure CSS light switch - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pure CSS light switch</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ @import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);
* { box-sizing: border-box;
}
body { background: #edece7;
}
.switch { display: block; position: relative; width: 70px; height: 100px; margin: 70px auto; border-radius: 50px; background: #e6e3da; background: linear-gradient(#e6e3da, #ffffff); border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: inset 0 7px 0 #fdfdfd, 0 2px 3px rgba(170, 160, 140, 0.3); cursor: pointer;
}
.switch:before { content: ""; position: absolute; top: -10px; bottom: -10px; left: -5px; right: -5px; z-index: -1; background: #f2f1ed; border-radius: inherit; box-shadow: 0 1px 1px rgba(174, 163, 145, 0.2), 0 3px 3px rgba(170, 160, 140, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 5px rgba(170, 160, 140, 0.5);
}
.switch:after { content: ""; position: absolute; width: 60px; height: 70px; border-radius: 50%; z-index: -1; left: 18px; top: 10px; background: linear-gradient(160deg, rgba(170, 160, 140, 0.7), rgba(170, 160, 140, 0)); background: -webkit-linear-gradient(290deg, rgba(170, 160, 140, 0.75), rgba(170, 160, 140, 0)); -webkit-filter: blur(1px);
}
/*
.switch span { display: block; width: 100%; height: 100%;
}
.switch span:after,
.switch span:before { content: ""; position: absolute; font-family: 'Source Sans Pro', sans-serif; color: rgba(170, 160, 140, 0.3); font-size: 20px; text-shadow: 0 1px 0 rgba(255,255,255,0.6), 0 -1px 0 rgba(0,0,0,0.1);
}
.switch span:before { content: "I"; top: -40px; left: 47%;
}
.switch span:after { content: "O"; bottom: -40px; left: 43%;
}
*/
#switch { clip: rect(0 0 0 0); position: absolute; visibility: hidden;
}
#switch:checked ~ .switch { background: linear-gradient(#f7f6f4, #ffffff); box-shadow: inset 0 -5px 0 #dbd3c8, 0 6px 5px rgba(170, 160, 140, 0.75), 3px 16px 5px rgba(170, 160, 140, 0.3); border-bottom: none;
}
#switch:checked ~ .switch:after { display: none;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <input type="checkbox" name="switch" id="switch">
<label class="switch" for="switch"><!--<span></span>--></label> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>
Pure CSS light switch - Script Codes CSS Codes
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);
* { box-sizing: border-box;
}
body { background: #edece7;
}
.switch { display: block; position: relative; width: 70px; height: 100px; margin: 70px auto; border-radius: 50px; background: #e6e3da; background: linear-gradient(#e6e3da, #ffffff); border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: inset 0 7px 0 #fdfdfd, 0 2px 3px rgba(170, 160, 140, 0.3); cursor: pointer;
}
.switch:before { content: ""; position: absolute; top: -10px; bottom: -10px; left: -5px; right: -5px; z-index: -1; background: #f2f1ed; border-radius: inherit; box-shadow: 0 1px 1px rgba(174, 163, 145, 0.2), 0 3px 3px rgba(170, 160, 140, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 5px rgba(170, 160, 140, 0.5);
}
.switch:after { content: ""; position: absolute; width: 60px; height: 70px; border-radius: 50%; z-index: -1; left: 18px; top: 10px; background: linear-gradient(160deg, rgba(170, 160, 140, 0.7), rgba(170, 160, 140, 0)); background: -webkit-linear-gradient(290deg, rgba(170, 160, 140, 0.75), rgba(170, 160, 140, 0)); -webkit-filter: blur(1px);
}
/*
.switch span { display: block; width: 100%; height: 100%;
}
.switch span:after,
.switch span:before { content: ""; position: absolute; font-family: 'Source Sans Pro', sans-serif; color: rgba(170, 160, 140, 0.3); font-size: 20px; text-shadow: 0 1px 0 rgba(255,255,255,0.6), 0 -1px 0 rgba(0,0,0,0.1);
}
.switch span:before { content: "I"; top: -40px; left: 47%;
}
.switch span:after { content: "O"; bottom: -40px; left: 43%;
}
*/
#switch { clip: rect(0 0 0 0); position: absolute; visibility: hidden;
}
#switch:checked ~ .switch { background: linear-gradient(#f7f6f4, #ffffff); box-shadow: inset 0 -5px 0 #dbd3c8, 0 6px 5px rgba(170, 160, 140, 0.75), 3px 16px 5px rgba(170, 160, 140, 0.3); border-bottom: none;
}
#switch:checked ~ .switch:after { display: none;
}
Developer | Hugo Giraudel |
Username | HugoGiraudel |
Uploaded | August 09, 2022 |
Rating | 4.5 |
Size | 4,088 Kb |
Views | 82,984 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Sass mixin for scrollbar styling | 2,400 Kb |
Stripe-a-gradient Sass function | 11,192 Kb |
CSS 3 progress bar | 2,808 Kb |
Demo Flexbox 3 | 2,822 Kb |
Off-canvas navigation | 3,864 Kb |
Pure CSS pie timer | 3,378 Kb |
Demo Flexbox 1 | 2,388 Kb |
Batman login form | 4,731 Kb |
Single element CSS character | 11,626 Kb |
A Pen by Hugo Giraudel | 3,061 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
My three.js practice | Esambino | 3,203 Kb |
A Different Type of Gallery | DonPage | 2,950 Kb |
CSS3 Selectables with information rollover | Jasonmayes | 9,565 Kb |
Eunice A | Ejbronze | 2,203 Kb |
Front in Aracaju Logo Pure CSS | Shankarcabus | 2,581 Kb |
Replace url via jquery | Serluk | 1,429 Kb |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
TweenMax transformOrigin Bubble | Nicolund | 2,209 Kb |
Calculator - codevember 08 - 2016 | Caiocares | 3,260 Kb |
JS Beispiel getElementsByClassName 3 | HSZG-Frontend-Kurs | 1,988 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!