Background animation for creating slider checkbox - HTML CSS CSS Form

HTML CSS examples for CSS Form:input checkbox

Description

Background animation for creating slider checkbox

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">

*{ padding:0; margin:0; }
body{ <!--from  w w  w. j  a v a2  s  .c  o  m-->
color:#333; 
background-color:#EEE; 
padding:20px; 
-webkit-font-smoothing:antialiased; }
.togglebox{
   display: inline-block;
   border: 1px solid #AAA;
   width: 90px;
   height: 30px;
   position: relative;
   color: #FFF;
   font-weight: bold;
   overflow: hidden;
   box-shadow: 0 1px 0 #FFF;
   border-radius: 20px;
}
.togglebox label {
   width: 200%;
   height: 100%;
   line-height: 30px;
   border-radius: 0.4em;
   position: absolute;
   top: 0;
   left: 0;
   z-index: 1;
   font-size: 1.1em;
   cursor: pointer;
   -webkit-transition: 0.12s;
   -moz-transition: 0.12s;
   transition: 0.12s;
}
.togglebox span {
   position: absolute;
   right: -100px;
   border-radius: 20px;
}
.togglebox label::before {
   content: 'ON';
   width: 62px;
   float: left;
   margin-right: -16px;
   padding-right: 13px;
   text-align: center;
   background: #007FEA;
   text-shadow: 0 -1px 0px #093B5C;
   box-shadow: 0 4px 5px -2px rgba(0,0,0,0.3) inset;
   border-top-left-radius: 20px;
   border-bottom-left-radius: 20px;
}
.togglebox label b {
   display: block;
   height: 100%;
   width: 30px;
   float: left;
   position: relative;
   z-index: 1;
   border: 1px solid #AAA;
   background: #F6F6F6;
   box-shadow: 0 4px 0 -2px #F1F1F1 inset, 0 2em 2em -2em #AAA inset, 0 0 2px rgba(0,0,0,.5);
   border-radius: 20px;
}
.togglebox label:hover b { background: #E5E5E5 }
.togglebox label::after {
   content: 'OFF';
   width: 62px;
   float: left;
   margin-left: -15px;
   padding-left: 13px;
   text-align: center;
   color: #999;
   background: #FFF;
   box-shadow: 0 4px 5px -2px rgba(0,0,0,0.3) inset;
   border-top-right-radius: 20px;
   border-bottom-right-radius: 20px;
}
.togglebox input:checked ~ label { left: -60px }
input[type=checkbox]{
   display:none;
}


      </style> 
 </head> 
 <body> 
  <div class="togglebox"> 
   <input type="checkbox" id="chkbx"> 
   <label for="chkbx"> <b></b> </label> 
  </div>  
 </body>
</html>

Related Tutorials