Pure CSS light switch

Developer
Size
4,088 Kb
Views
82,984

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 Previews

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;
}
Pure CSS light switch - Script Codes
Pure CSS light switch - Script Codes
Home Page Home
Developer Hugo Giraudel
Username HugoGiraudel
Uploaded August 09, 2022
Rating 4.5
Size 4,088 Kb
Views 82,984
Do you need developer help for Pure CSS light switch?

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!

Hugo Giraudel (HugoGiraudel) Script Codes
Create amazing SEO content with AI!

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!