Bootstrap 3 - iOS switch/ CSS only

by Hifni Nazeer

HTML

<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<div class="container">
    <div class="row">
	<div class="col-sm-3">
		<h5>Default</h5>
		<div class="checkbox checkbox-slider--b-flat">
			<label>
				<input type="checkbox"><span>Default</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat">
			<label>
				<input type="checkbox" checked=""><span>checked</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat">
			<label>
				<input type="checkbox" disabled=""><span>disabled</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat">
			<label>
				<input type="checkbox" disabled="" checked=""><span>disabled checked</span>
			</label>
		</div>
	</div>
	<div class="col-sm-3">
		<h5>Small</h5>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-sm">
			<label>
				<input type="checkbox"><span>small</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-sm">
			<label>
				<input type="checkbox" checked=""><span>checked</span>
			</label>
		</div>
	</div>
	<div class="col-sm-3">
		<h5>Medium</h5>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-md">
			<label>
				<input type="checkbox"><span>medium</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-md">
			<label>
				<input type="checkbox" checked=""><span>checked</span>
			</label>
		</div>
	</div>
	<div class="col-sm-3">
		<h5>Large</h5>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-lg">
			<label>
				<input type="checkbox"><span>large</span>
			</label>
		</div>
		<div class="checkbox checkbox-slider--b-flat checkbox-slider-lg">
			<label>
				<input type="checkbox" checked=""><span>checked</span>
			</label>
		</div>
	</div>
</div>
</div>

CSS

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
    margin: 10px;
}

/*******************************************************
Slider B-flat
*******************************************************/
.checkbox-slider--b-flat {
  position: relative;
}

.checkbox-slider--b-flat input {
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  height: 0%;
  margin: 0 0;
  cursor: pointer;
  opacity: 0;
  filter: alpha(opacity=0);
}
.checkbox-slider--b-flat input + span {
  cursor: pointer;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.checkbox-slider--b-flat input + span:before {
  position: absolute;
  left: 0px;
  display: inline-block;
}
.checkbox-slider--b-flat input + span > h4 {
  display: inline;
}
.checkbox-slider--b-flat input + span {
  padding-left: 40px;
}
.checkbox-slider--b-flat input + span:before {
  content: "";
  height: 20px;
  width: 40px;
  background: rgba(100, 100, 100, 0.2);
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.8);
  transition: background 0.2s ease-out;
}
.checkbox-slider--b-flat input + span:after {
  width: 20px;
  height: 20px;
  position: absolute;
  left: 0px;
  top: 0;
  display: block;
  background: #ffffff;
  transition: margin-left 0.1s ease-in-out;
  text-align: center;
  font-weight: bold;
  content: "";
}
.checkbox-slider--b-flat input:checked + span:after {
  margin-left: 20px;
  content: "";
}
.checkbox-slider--b-flat input:checked + span:before {
  transition: background 0.2s ease-in;
}
.checkbox-slider--b-flat input + span {
  padding-left: 40px;
}
.checkbox-slider--b-flat input + span:before {
  border-radius: 20px;
  width: 40px;
}
.checkbox-slider--b-flat input + span:after {
  background: #ffffff;
  content: "";
  width: 20px;
  border: solid transparent 2px;
 ...

JavaScript

/* Latest compiled and minified JavaScript included as External Resource */