Menu
Category

Author 12 Dec 2017 in Checkbox | 0 comments

VIEW DEMO   DOWNLOAD

Android On/Off Switch Button

Simple and fun demo of CSS checkboxes that have a cool Android On/Off Switch Button animation. Not really UI practical, but overall a cool demonstration.

HTML

Code
<div align="center">
  <h2>Android On/Off Switch Button</h2>
<div class="onoffswitch">

  <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
  <label class="onoffswitch-label" for="myonoffswitch">
  <div class="onoffswitch-inner">
  <div class="onoffswitch-active"><div class="onoffswitch-switch">ON</div></div>
  <div class="onoffswitch-inactive"><div class="onoffswitch-switch">OFF</div></div>
  </div>
  </label>
  </div>  
</div>


CSS

Code
body {
  background: #eff;
}

.onoffswitch {
  position: relative; width: 100px;
  -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
  }
  .onoffswitch-checkbox {
  display: none;
  }
  .onoffswitch-label {
  display: block; overflow: hidden; cursor: pointer;
  border: 0px solid #999999; border-radius: 0px;
  }
  .onoffswitch-inner {
  width: 200%; margin-left: -100%;
  -moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
  -o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
  }
  .onoffswitch-inner > div {
  float: left; position: relative; width: 50%; height: 30px; padding: 0; line-height: 30px;
  font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
  }
  .onoffswitch-inner .onoffswitch-active {
  padding-left: 15px;
  background-color: #C2C2C2; color: #FFFFFF;
  }
  .onoffswitch-inner .onoffswitch-inactive {
  padding-right: 15px;
  background-color: #C2C2C2; color: #FFFFFF;
  text-align: right;
  }
  .onoffswitch-switch {
  width: 40px; margin: 0px; text-align: center;
  border: 0px solid #999999;border-radius: 0px;
  position: absolute; top: 0; bottom: 0;
  }
  .onoffswitch-active .onoffswitch-switch {
  background: #27A1CA; left: 0;
  }
  .onoffswitch-inactive .onoffswitch-switch {
  background: #A1A1A1; right: 0;
  }
  .onoffswitch-active .onoffswitch-switch:before {
  content: " "; position: absolute; top: 0; left: 40px;
  border-style: solid; border-color: #27A1CA transparent transparent #27A1CA; border-width: 15px 10px;
  }
  .onoffswitch-inactive .onoffswitch-switch:before {
  content: " "; position: absolute; top: 0; right: 40px;
  border-style: solid; border-color: transparent #A1A1A1 #A1A1A1 transparent; border-width: 15px 10px;
  }
  .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
  }

Views: 1660 | Rating: 0.0/0

Leave a comment

%