<div class="container">
<fieldset id="c-group">
<label for="c1">
<input type="checkbox" id="c1" name="c-group" checked>
<span class="label-text">cats are good</span>
</label>
<label for="c2">
<input type="checkbox" id="c2" name="c-group">
<span class="label-text">cats are the best</span>
</label>
<label for="c3">
<input type="checkbox" id="c3" name="c-group">
<span class="label-text">i love cats</span>
</label>
<label for="c4">
<input type="checkbox" id="c4" name="c-group" disabled>
<span class="label-text">i want to pet all the cats <span class="aside">(checkbox disabled)</span></span>
</label>
<label for="c5">
<input type="checkbox" id="c5" name="c-group" disabled checked>
<span class="label-text">cats are nice <span class="aside">(checkbox checked + disabled)</span></span>
</label>
</fieldset>
<fieldset id="r-group">
<label for="r1">
<input type="radio" id="r1" name="r-group">
<span class="label-text">dogs are good</span>
</label>
<label for="r2">
<input type="radio" id="r2" name="r-group">
<span class="label-text">dogs are the best</span>
</label>
<label for="r3">
<input type="radio" id="r3" name="r-group">
<span class="label-text">i love dogs</span>
</label>
<label for="r4">
<input type="radio" id="r4" name="r-group" disabled>
<span class="label-text">i want to pet all the dogs <span class="aside">(radio disabled)</span></span>
</label>
<label for="r5">
<input type="radio" id="r5" name="r-group" disabled checked>
<span class="label-text">dogs are nice <span class="aside">(radio checked + disabled)</span></span>
</label>
</fieldset>
<fieldset id="c-group-filled">
<label for="cf1">
<input type="checkbox" id="cf1" name="c-group-filled" class="filled" checked>
<span class="label-text">cats are good</span>
</label>
<label for="cf2">
<input type="checkbox" id="cf2" name="c-group-filled" class="filled">
<span class="label-text">cats are the best</span>
</label>
<label for="cf3">
<input type="checkbox" id="cf3" name="c-group-filled" class="filled">
<span class="label-text">i love cats</span>
</label>
<label for="cf4">
<input type="checkbox" id="cf4" name="c-group-filled" class="filled" disabled>
<span class="label-text">i want to pet all the cats <span class="aside">(checkbox disabled)</span></span>
</label>
<label for="cf5">
<input type="checkbox" id="cf4" name="c-group-filled" class="filled" disabled checked>
<span class="label-text">cats are nice <span class="aside">(checkbox checked + disabled)</span></span>
</label>
</fieldset>
</div>
// radios
@checkbox-size: 16px;
@margin: 16px;
@margin-small: @margin / 2;
@text-lighter: #ccc;
@brand: #12CBC4;
body {
font-family: sans-serif;
color: #444;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
width: 100vw;
align-items: center;
margin: 30px;
}
fieldset {
border: none;
display: flex;
flex-direction: column;
margin: 20px;
align-items: flex-start;
min-width: 400px;
}
label {
display: flex;
flex-direction: row;
align-items: center;
}
.aside {
color: @text-lighter;
}
input {
position: relative !important;
appearance: none;
margin: @margin-small;
box-sizing: content-box;
overflow: hidden;
// circle
&:before {
content: '';
display: block;
box-sizing: content-box;
width: @checkbox-size;
height: @checkbox-size;
border: 2px solid @text-lighter;
transition: 0.2s border-color ease;
}
&:checked:before {
border-color: @brand;
transition: 0.5s border-color ease;
}
&:disabled:before {
border-color: @text-lighter;
background-color: @text-lighter;
}
// dot
&:after {
content: '';
display: block;
position: absolute;
box-sizing: content-box;
top: 50%;
left: 50%;
transform-origin: 50% 50%;
background-color: @brand;
width: @checkbox-size;
height: @checkbox-size;
border-radius: 100vh;
transform: translate(-50%, -50%) scale(0);
}
&[type="radio"] {
&:before {
border-radius: 100vh;
}
&:after {
width: @checkbox-size;
height: @checkbox-size;
border-radius: 100vh;
transform: translate(-50%, -50%) scale(0);
}
&:checked:after {
animation: toggleOnRadio 0.2s ease forwards;
}
}
&[type="checkbox"] {
&:before {
border-radius: @checkbox-size / 4;
}
&:after {
width: @checkbox-size * 0.6;
height: @checkbox-size;
border-radius: 0;
transform: translate(-50%, -85%) scale(0) rotate(45deg);
background-color: transparent;
box-shadow: 4px 4px 0px 0px @brand;
}
&:checked:after {
animation: toggleOnCheckbox 0.2s ease forwards;
}
}
&[type="checkbox"].filled {
&:before {
border-radius: @checkbox-size / 4;
transition: 0.2s border-color ease, 0.2s background-color ease;
}
&:checked:not(:disabled):before {
background-color: @brand;
}
&:not(:disabled):after {
box-shadow: 4px 4px 0px 0px white;
}
}
}
@keyframes toggleOnCheckbox {
0% {
opacity: 0;
transform: translate(-50%, -85%) scale(0) rotate(45deg);
}
70% {
opacity: 1;
transform: translate(-50%, -85%) scale(0.9) rotate(45deg);
}
100% {
transform: translate(-50%, -85%) scale(0.8) rotate(45deg);
}
}
@keyframes toggleOnRadio {
0% {
opacity: 0;
transform: translate(-50%, -50%) scale(0);
}
70% {
opacity: 1;
transform: translate(-50%, -50%) scale(0.9);
}
100% {
transform: translate(-50%, -50%) scale(0.8);
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.