Skip to content

Instantly share code, notes, and snippets.

@kishmiryan-karlen
Last active May 6, 2019 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishmiryan-karlen/a3bb5f101868f52bfc1a to your computer and use it in GitHub Desktop.
Save kishmiryan-karlen/a3bb5f101868f52bfc1a to your computer and use it in GitHub Desktop.
A CSS, which turns boring checkboxes into nice On/Off switches. Just include it in your styles.
input[type="checkbox"] {
-webkit-appearance: none;
border: 2px solid #bdbdbd;
width: 61px;
height: 27px;
border-radius: 2px;
display: inline-block;
position: relative;
outline: none;
cursor: pointer;
}
/* Text content */
input[type="checkbox"]:before {
top: 0px;
left: 0px;
width: 57px;
height: 23px;
color: #bdbdbd;
display: block;
font-size: 12px;
content: 'ON \00a0OFF';
line-height: 23px;
position: absolute;
text-align: center;
font-family: OpenSans_Bold, arial;
}
/* Rectangle to be switched */
input[type="checkbox"]:after {
top: 2px;
left: 2px;
content: '';
width: 25px;
height: 19px;
display: block;
position: absolute;
background: #bdbdbd;
-webkit-transition: all .3s ease-out;
}
/* Checked states */
input[type="checkbox"]:checked {
border-color: #25bfa1;
}
input[type="checkbox"]:checked:before {
color: #25bfa1;
}
input[type="checkbox"]:checked:after {
left: 29px;
background: #25bfa1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment