JSFiddle - React, Tailwind, and code Playground
by Petra1999
HTML
<div class="custom-checkbox">
<input type="checkbox" id="my-checkbox">
<label for="my-checkbox">
<i class="fake-checkbox"></i>
<span>Text</span>
</label>
</div>
SCSS
.custom-checkbox {
display: block;
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
label {
display: block;
cursor: pointer;
vertical-align: sub;
}
}
.fake-checkbox {
position: relative;
display: inline-block;
color: red;
width: 1em;
height: 1em;
z-index: 0;
border: 2px solid;
border-radius: 3px;
vertical-align: middle;
margin-right: 0.5em;
margin-top: -2px;
transition: color 0.15s ease;
&::after {
opacity: 0;
content: '✓';
position: absolute;
font-size: 1.4em;
top: 0;
left: -1px;
font-weight: bold;
transition: opacity 0.15s ease;
line-height: 1;
}
}
input[type='checkbox'] {
width: auto !important;
opacity: 0.0001 !important;
position: absolute;
left: 0.25em;
top: 0.25em;
margin: 0;
padding: 0;
&:checked+label .fake-checkbox {
color: green;
&::after {
opacity: 1;
}
}
}