I've been trying to make a toggleable button through css, and I've been wondering if there's a way to transition between these two states smoothly when the checkbox is clicked, I've managed to do it without animations but it'd be neat if it was possible to anime the transition
toggle-button {
position: relative;
display: inline-block;
width: 120px;
height: 40px;
margin-left: 100px;
}
.toggle-button input{
opacity: 0;
height: 0;
width: 0;
}
.options-wrapper {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to right, white 50%, gray 50%);
border-radius:3px;
}
.button-options {
display: grid;
grid-template-columns: 1fr 1fr;
justify-items: center;
align-items: center;
height: 100%;
width: 100%;
background: linear-gradient(to right, black 50%, white 50%);
-webkit-background-clip: text;
-webkit-transition: .4s;
transition: .4s;
cursor: pointer;
}
.toggle-button input:checked + .options-wrapper {
background: linear-gradient(to right, gray 50%, white 50%);
}
.toggle-button input:checked + .options-wrapper > .button-options {
background: linear-gradient(to right, white 50%, black 50%);
-webkit-background-clip: text;
}
@keyframes shiftOpacity {
from { opacity: 0; }
to { opacity: 1; }
}
.button-options > p {
color: transparent
}
<label class="toggle-button">
<input type="checkbox">
<div class="options-wrapper">
<div class="button-options">
<p>Daily</p>
<p>Hourly</p>
</div>
</div>
</label>