Skip to content

Instantly share code, notes, and snippets.

@elifry
Created October 3, 2021 21:42
Show Gist options
  • Save elifry/63d94083dacfb9d93b9c428788d80c17 to your computer and use it in GitHub Desktop.
Save elifry/63d94083dacfb9d93b9c428788d80c17 to your computer and use it in GitHub Desktop.
CSS for checkbox
input[type='checkbox'] {
opacity: 0;
}
input[type='checkbox'] + label {
font: auto;
position: absolute;
// top: 25px;
display: flex;
align-items: center;
transition: color 250ms cubic-bezier(.4,.0,.23,1);
padding-top: 0.2em;
}
input[type='checkbox'] + label > span {
font: 28px sans-serif;
display: flex;
justify-content: center;
margin-right: 1em;
width: 1em;
height: 1em;
background: white;
border: 2px solid #9E9E9E; // border of box
border-radius: 2px;
cursor: pointer;
transition: all 250ms cubic-bezier(.4,.0,.23,1);
}
input[type='checkbox'] + label:hover > span,
input[type='checkbox']:focus + label > span {
background: white;
}
input[type='checkbox']:checked + label > ins {
height: 100%;
}
input[type='checkbox']:checked + label > span {
border: 0.5em solid #F1C232;
}
input[type='checkbox']:checked + label > span:before {
content: "";
position: absolute;
top: 0.5em;
left: 0.25em;
border-right: 2px solid transparent;
border-bottom: 2px solid transparent;
transform: rotate(45deg);
transform-origin: 0 100%;
animation: checkbox-check 125ms 250ms cubic-bezier(.4,.0,.23,1) forwards;
}
@keyframes checkbox-check {
0% {
width: 0;
height: 0;
border-color: #212121;
transform: translate3d(0,0,0) rotate(45deg);
}
33% {
width: 0.2em;
height: 0;
transform: translate3d(0,0,0) rotate(45deg);
}
100% {
width: 0.3em;
height: 0.65em;
border-color: #212121;
transform: translate3d(0,-.5em,0) rotate(45deg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment