Skip to content

Instantly share code, notes, and snippets.

@lenards
Forked from gladchinda/toggle-switch.css
Created March 20, 2019 18:21
Show Gist options
  • Save lenards/a3e627a55cb7ed23ff34dbc8ea975a6e to your computer and use it in GitHub Desktop.
Save lenards/a3e627a55cb7ed23ff34dbc8ea975a6e to your computer and use it in GitHub Desktop.
/* Styles for hiding the native checkbox */
input[type='checkbox'].check-custom {
top: 0;
left: 0;
width: 0;
height: 0;
opacity: 0;
filter: alpha(opacity=0);
position: absolute;
visibility: hidden;
}
/* Styles for the basic appearance of the toggle switch */
input[type='checkbox'].check-custom.toggle-switch ~ .check-toggle {
width: 1.5rem;
height: 1rem;
position: relative;
display: inline-block;
vertical-align: middle;
cursor: pointer;
}
/* Common styles for the ::before and ::after pseudo-elements of the toggle switch */
input[type='checkbox'].check-custom.toggle-switch ~ .check-toggle::before,
input[type='checkbox'].check-custom.toggle-switch ~ .check-toggle::after {
content: '';
top: 0;
left: 0;
position: absolute;
}
/* Styles for the ::before pseudo-element (the outer frame) of the toggle switch */
input[type='checkbox'].check-custom.toggle-switch ~ .check-toggle::before {
width: 100%;
height: 100%;
border-radius: 0.5rem;
background: #dbdbdb;
}
/* Styles for the ::after pseudo-element (the inner slider) of the toggle switch */
input[type='checkbox'].check-custom.toggle-switch ~ .check-toggle::after {
width: 0.75rem;
height: 0.75rem;
margin: 0.125rem;
border-radius: 50%;
background: #ffffff;
}
/* Styles for the ::before pseudo-element of the toggle switch in checked or enabled state */
input[type='checkbox'].check-custom.toggle-switch:checked ~ .check-toggle::before {
border-color: #61bf9e;
background: #61bf9e;
}
/* Styles for the ::after pseudo-element of the toggle switch in checked or enabled state */
input[type='checkbox'].check-custom.toggle-switch:checked ~ .check-toggle::after {
left: auto;
right: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment