پیشنمایش زنده
کد HTML
<label class="container">
<input type="checkbox" checked="checked" />
<div class="checkmark"></div>
</label>
کد CSS
/* Checkbox Container */
.container {
position: relative;
display: inline-flex;
align-items: center;
cursor: pointer;
font-size: 20px;
user-select: none;
padding: 1em;
gap: 0.5em;
}
/* Hidden Input */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Checkmark Base */
.checkmark {
position: relative;
height: 1.5em;
width: 1.5em;
background: linear-gradient(135deg, #ffffff, #f0f0f5);
border: 0.15em solid #b0b0c0;
border-radius: 0.3em;
box-shadow:
inset 0 2px 4px rgba(255, 255, 255, 0.8),
0 2px 6px rgba(0, 0, 0, 0.1);
transition:
all 0.3s ease,
transform 0.2s ease;
}
/* Checkmark Decorative Elements */
.checkmark::before {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 0.8em;
height: 0.2em;
background: transparent;
border-radius: 2em;
transform: translate(-50%, -50%) scale(0);
transition:
transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55),
background 0.2s ease;
}
/* Checked State */
.container input:checked ~ .checkmark {
background: linear-gradient(135deg, #f44336, #ef5350);
border-color: #d32f2f;
box-shadow:
0 0 8px rgba(244, 67, 54, 0.5),
inset 0 2px 4px rgba(255, 255, 255, 0.3);
}
.container input:checked ~ .checkmark::before {
background: #ffffff;
transform: translate(-50%, -50%) scale(1) rotate(-45deg);
box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}
/* Checkmark Secondary Element */
.checkmark::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 0.2em;
height: 0.8em;
background: transparent;
border-radius: 2em;
transform: translate(-50%, -50%) scale(0);
transition:
transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55),
background 0.2s ease;
}
.container input:checked ~ .checkmark::after {
background: #ffffff;
transform: translate(-50%, -50%) scale(1) rotate(-45deg);
transition-delay: 0.1s;
}
/* Hover State */
.container:hover .checkmark {
border-color: #8888a0;
box-shadow:
inset 0 2px 4px rgba(255, 255, 255, 0.8),
0 4px 12px rgba(0, 0, 0, 0.15);
}
/* Focus State */
.container input:focus + .checkmark {
border-color: #ef5350;
box-shadow:
0 0 12px rgba(244, 67, 54, 0.6),
inset 0 2px 4px rgba(255, 255, 255, 0.8);
}
/* Click Animation */
.container input:checked ~ .checkmark {
animation: bounceIn 0.4s ease-out;
}
/* Active Press Effect */
.container:active .checkmark {
transform: scale(0.9);
box-shadow:
inset 0 1px 2px rgba(255, 255, 255, 0.8),
0 1px 4px rgba(0, 0, 0, 0.1);
}
/* Bounce Animation */
@keyframes bounceIn {
0% {
transform: scale(0.7);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}