checkbox На чистом CSS

checkbox На чистом CSS

by Сергей Тарасевич

HTML

<div class="checkbox-style">
  <input id="checked_html_1" type="checkbox" checked="" name="checked_html_1" value="1">
  <label for="checked_html_1">
    <span class="checked"></span>
    <span class="toggle"></span>
    <span class="unchecked"></span>
  </label>
</div>

<div class="checkbox-style">
  <input id="checked_html_2" type="checkbox" name="checked_html_2" value="1">
  <label for="checked_html_2">
    <span class="checked"></span>
    <span class="toggle"></span>
    <span class="unchecked"></span>
  </label>
</div>

<div class="checkbox-style">
  <input id="checked_html_3" type="checkbox" checked="" name="checked_html_3" value="1">
  <label for="checked_html_3">
    <span class="checked"></span>
    <span class="toggle"></span>
    <span class="unchecked"></span>
  </label>
</div>

CSS

.checkbox-style {
  cursor: pointer;
  display: inline-block;
  margin-left: 10px;
  overflow: hidden;
  position: relative;
  vertical-align: middle;
  height: 26px;
  width: 50px;
}

.checkbox-style input[type="checkbox"] {
  margin: 0;
  opacity: 0;
  position: absolute;
  height: 15px;
  width: 37px;
}

.checkbox-style label {
  background: #d9534f;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  margin: 0;
  overflow: hidden;
  padding: 2px 0;
  -webkit-transition: all ease .3s;
  -moz-transition: all ease .3s;
  -ms-transition: all ease .3s;
  -o-transition: all ease .3s;
  transition: all ease .3s;
  height: 26px;
  width: 100%;
  z-index: 1;
}

.checkbox-style input[type=checkbox]:checked + label {
  background: #5cb85c;
}

.checkbox-style label > * {
  display: inline-block;
  vertical-align: top;
  -webkit-transition: all ease .3s;
  -moz-transition: all ease .3s;
  -ms-transition: all ease .3s;
  -o-transition: all ease .3s;
  transition: all ease .3s;
}

.checkbox-style .checked,
.checkbox-style .toggle,
.checkbox-style .unchecked {
  cursor: pointer;
  font-size: 22px;
  font-weight: bold;
  position: relative;
  height: 22px;
  width: 22px;
}

.checkbox-style .checked {
  background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAYAAAAGAB4TKWmAAAAbklEQVRIx+2SwQmAMBAEV+3GKmzCpBox3dikMH4iBDEP8e6jmWcgM0cuUqPxBGD0lM/ADqzleW8ll7RJGiR1XpMDJGt5+KEcWPLSXORTvrjfRYD4+lmAVESCqbwSiabySsTtt5wRe/kl4iNvfIMDBz/nw85eXwAAAAAASUVORK5CYII=) no-repeat center center;
  color: #ffffff;
  margin-left: -22px;
}

.checkbox-style input[type=checkbox]:checked + label .checked {
  margin-left: 2px;
}

.checkbox-style .toggle {
  background: #ffffff;
  box-shadow: 0 0 10px -2px #000, inset 0 0 10px -4px rgba(0, 0, 0, 0.5);
  margin: 0 2px;
}

.checkbox-style .unchecked {
  background:...