پیشنمایش زنده
کد HTML
<div class="checkbox-container">
<input class="checkbox-input" id="animated-checkbox" type="checkbox" />
<label class="checkbox" for="animated-checkbox">
<span class="line line1"></span>
<span class="line line2"></span>
</label>
</div>
کد CSS
/* Checkbox Container */
.checkbox-container {
display: flex;
justify-content: center;
align-items: center;
}
/* Hidden Checkbox Input */
.checkbox-input {
display: none;
}
/* Checkbox Label */
.checkbox {
position: relative;
width: 50px;
height: 50px;
background: #e0e0e0;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
box-shadow:
inset -4px -4px 8px #ffffff,
inset 4px 4px 8px #b0b0b0;
}
/* X Mark Lines */
.line {
position: absolute;
width: 30px;
height: 4px;
background: #a0a0a0; /* Disabled color */
border-radius: 2px;
transition: all 0.3s ease-in-out;
}
/* X Mark Line 1 */
.line1 {
transform: rotate(45deg);
}
/* X Mark Line 2 */
.line2 {
transform: rotate(-45deg);
}
/* Checked State */
.checkbox-input:checked + .checkbox {
background: #d4e9d4; /* Light green background */
}
.checkbox-input:checked + .checkbox .line1 {
transform: rotate(50deg) translateX(-3px) translateY(8px) scaleX(0.6);
background: #169c1fff;
}
.checkbox-input:checked + .checkbox .line2 {
transform: rotate(-50deg) translateX(6px) translateY(3px); /* Second line in tick's opposite direction */
background: #169c1fff;
}