CSSだけで作るシンプルでサイズや色の変更が容易なトグルボタン風のcheckboxです。ブラウザ本来のcheckboxのアピアランスを消して、::after疑似要素で描画しています。
設置はいたって簡単で、
<input type="checkbox">と記述するだけです。
サンプルをクリックしてチェックすると背景色が、1番目と2番目は緑、3番目と4番目は青、5番目と6番目は赤とそれぞれ変わります。
サンプルのhtmlソース
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
サンプルのCSSソース
input {
position: relative;
margin: 0 10px;
border-radius: 20px;
background: #999;
outline: 0;
-webkit-appearance: none;
cursor: pointer;
}
input::after {
content: '';
position: absolute;
top: 2px;
left: 2px;
display: block;
width: calc((100% - 4px) / 2);
height: calc(100% - 4px);
border-radius: 50%;
background: #eee;
transition: all .1s linear;
}
input:checked {
background: #5b5;
}
input:checked::after {
transform: translateX(100%);
}
input:nth-child(1) { width: 56px; height: 30px; }
input:nth-child(2) { width: 48px; height: 26px; }
input:nth-child(3) { width: 40px; height: 22px; }
input:nth-child(4) { width: 32px; height: 18px; }
input:nth-child(5) { width: 24px; height: 14px; }
input:nth-child(6) { width: 20px; height: 12px; }
input:checked:nth-child(3),
input:checked:nth-child(4) { background: #37d; }
input:checked:nth-child(5),
input:checked:nth-child(6) { background: #d37; }