CSS:
[type="checkbox"] {
width: 44px; height: 26px;
position: absolute;
opacity: 0;
pointer-events: none;
}
/* 开关样式 */
.cs-switch {
display: inline-block;
width: 44px; height: 26px;
border: 2px solid;
border-radius: 26px;
background-color: currentColor;
box-sizing: border-box;
color: silver;
transition: all .2s;
cursor: pointer;
}
.cs-switch::before {
content: "";
display: block;
width: 22px; height: 22px;
border-radius: 50%;
background-color: #fff;
transition: margin-left .2s;
}
/* 若干状态控制 */
:active:not(:disabled) + .cs-switch::before {
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.1);
}
:checked + .cs-switch {
color: deepskyblue;
}
:checked + .cs-switch::before {
margin-left: 18px;
}
:focus-visible + .cs-switch {
outline: 1px dotted Hightlight;
outline: 5px auto -webkit-focus-ring-color;
}
:disabled + .cs-switch {
opacity: .4;
cursor: default;
}