پیشنمایش زنده
کد HTML
<label class="checkbox-container">
<input checked="" type="checkbox" />
<div class="checkmark"></div>
</label>
کد CSS
/* Container styling */
.checkbox-container {
display: flex;
align-items: center;
font-size: 1em;
cursor: pointer;
user-select: none;
}
/* Hide default checkbox */
.checkbox-container input {
display: none;
}
/* Scoped custom properties */
.checkbox-container {
--checkmark-size: 2.5em;
--border-color: #333;
--checked-bg-color: #6bc6d9;
--checked-border-color: #4ca3b1;
--checkmark-color: white;
--focus-outline-color: rgba(255, 107, 107, 0.5);
}
/* Checkmark styling */
.checkmark {
width: var(--checkmark-size);
height: var(--checkmark-size);
border: 2px solid var(--border-color);
border-radius: 0.25em;
background-color: transparent;
position: relative;
margin-right: 0.5em;
transition:
background-color 0.3s ease,
border-color 0.3s ease,
box-shadow 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
/* Checked state */
.checkbox-container input:checked + .checkmark {
background-color: var(--checked-bg-color);
border-color: var(--checked-border-color);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
/* Checkmark icon */
.checkmark::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 0.75em;
height: 0.75em;
background-color: transparent;
border-radius: 0.1em;
transform: translate(-50%, -50%);
transition:
background-color 0.3s ease,
transform 0.3s ease;
}
.checkbox-container input:checked + .checkmark::after {
background-color: var(--checkmark-color);
transform: scale(1);
animation: checkmark-fade-in 0.3s ease forwards;
}
/* Hover and Focus */
.checkmark:hover {
border-color: var(--checked-bg-color);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
.checkbox-container input:focus + .checkmark {
outline: none;
box-shadow: 0 0 0 2px var(--focus-outline-color);
}
/* Checkmark animation */
@keyframes checkmark-fade-in {
0% {
opacity: 0;
transform: translate(-50%, -50%) scale(0.5);
}
100% {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
}