<p>Can you guess how the animation is working without reading the source code?</p>
<input type="checkbox" id="toggle_checkbox">
<label for="toggle_checkbox"></label>
* {
tap-highlight-color: transparent;
}
html,
body {
height: 100%;
}
body {
margin: 0;
background-color: #f3fbff;
}
p {
position: fixed;
top: 0;
right: 0;
left: 0;
padding: 10px;
color: #143240;
text-align: center;
font-size: 14px;
font-family: Helvetica, serif;
}
#toggle_checkbox {
display: none;
}
label {
position: absolute;
top: 50%;
right: 0;
left: 0;
display: block;
width: 140px;
height: 70px;
margin: 0 auto;
transform: translateY(-50%);
cursor: pointer;
}
label:before {
top: 8px;
left: 8px;
width: 54px;
height: 54px;
border: 3px solid red;
}
label:after {
top: 0;
right: 0;
width: 140px;
height: 70px;
border: 3px solid #143240;
}
label:before,
label:after {
content: "";
position: absolute;
border-radius: 50px;
box-sizing: border-box;
transition: 0.5s ease top, 0.5s ease left, 0.5s ease right, 0.5s ease width,
0.5s ease height, 0.5s ease border-color;
}
#toggle_checkbox:checked + label:before {
top: 0;
left: 0;
width: 140px;
height: 70px;
border-color: #143240;
}
#toggle_checkbox:checked + label:after {
top: 8px;
right: 8px;
width: 54px;
height: 54px;
border-color: red;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.