It was supposed to transition smoothly
- to colorful when hover or active
- to gray when deactivated and no hover
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0%;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 17px;
background-color: gray;
-webkit-transition: 0.4s;
transition: 0.4s;
}
.slider::before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
border-radius: 50%;
-webkit-transition: 0.4s;
transition: 0.4s;
}
input + .slider:hover,
input:checked + .slider {
background: linear-gradient(
to top right,
yellow,
orange
);
}
input:checked + .slider::before {
-webkit-transform: translateX(26px);
transform: translateX(26px);
}
<label class="switch">
<input type="checkbox" />
<span class="slider"></span>
</label>
But it blinks in between some of these transitions - hover exit, deactivation click - and does not transition smoothly when hovered on. I got a feeling it has to do with something overlapping, but do not quite understand why. Any help?
Thanks in advance!