Skip to content

Instantly share code, notes, and snippets.

@mrtag23
Created April 19, 2018 16:55
Show Gist options
  • Save mrtag23/a0fa4d547071c80fb9d827ba6e1e2ffc to your computer and use it in GitHub Desktop.
Save mrtag23/a0fa4d547071c80fb9d827ba6e1e2ffc to your computer and use it in GitHub Desktop.
Pure CSS checkbox styling.
// Custom checkbox styling.
.checkbox-wrapper {
$checkbox-height: 16px;
$checkbox-width: 16px;
label {
display: inline-block;
padding-left: ($checkbox-width + 15px);
position: relative;
&:after,
&:before {
content: '';
display: inline-block;
position: absolute;
}
// Before element is representing the checkbox's square.
&:before {
background-color: #fff;
border: solid 1px #979797;
border-radius: 2px;
box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
height: $checkbox-height;
left: 0;
top: 5px;
width: $checkbox-width;
}
// After element is representing the checkbox's check mark.
&:after {
border-left: 3px solid $aqua;
border-bottom: 3px solid $aqua;
height: 8px;
left: 4px;
top: 4px;
transform: rotate(-45deg);
width: 15px;
}
}
// Check/un-check interactions.
.checkbox-element {
opacity: 0;
& + label::after {
content: none;
}
&:checked + label::after {
content: '';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment