Include pointer-events: none;
in the style of .cbx span:first-child:before
. The issue is caused by the animation.
In the .cbx span:first-child:before
section, we are transitioning the content:""
from scale(0)
and opacity:1
to scale(3.5)
and opacity:0
respectively. Essentially, we are only hiding that object with opacity, meaning the object will still be there and clickable. This is why it's necessary to add pointer-events:none
to the .cbx span:first-child:before
style.
To test this, simply select the 4th checkbox and examine it using the
.inp-cbx:checked + .
cbx span:first-child:before
style. Change the opacity from 0 to
opacity:1
. You will see something like what is shown below.
https://i.sstatic.net/GzeEN.png
In the image above, you can observe that the span:before
of the 4th checkbox covers the 3rd checkbox and remains clickable. So, when you click on the 3rd checkbox, it actually registers as a click on the 4th one.
Explore the code snippet provided below:
.cbx {
margin: auto;
margin-top: 2px;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 18px;
height: 18px;
border-radius: 3px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx span:first-child svg {
position: absolute;
top: 3px;
left: 2px;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #506EEC;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 50%;
pointer-events:none;
}
.cbx span:last-child {
padding-left: 8px;
}
.cbx:hover span:first-child {
border-color: #506EEC;
}
.inp-cbx:checked + .cbx span:first-child {
background: #506EEC;
border-color: #506EEC;
animation: wave 0.4s ease;
}
.inp-cbx:checked + .cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx:checked + .cbx span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
@keyframes wave {
50% {
transform: scale(0.9);
}
}
<div class="ax-cb-div">
<input class="inp-cbx" id="1" type="checkbox" style="display: none;"/>
<label for="1" class="cbx"><span>
<svg width="12px" height="10px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>Checkbox number 1</span>
</label>
</div>
<div class="ax-cb-div">
<input class="inp-cbx" id="2" type="checkbox" style="display: none;"/>
<label for="2" class="cbx"><span>
<svg width="12px" height="10px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>Checkbox number 2</span>
</label>
</div>
<div class="ax-cb-div">
<input class="inp-cbx" id="3" type="checkbox" style="display: none;"/>
<label for="3" class="cbx"><span>
<svg width="12px" height="10px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>Checkbox number 3</span>
</label>
</div>
<div class="ax-cb-div">
<input class="inp-cbx" id="4" type="checkbox" style="display: none;"/>
<label for="4" class="cbx"><span>
<svg width="12px" height="10px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>Checkbox number 4</span>
</label>
</div>