效果演示
完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input{
appearance: none;
width: 80px;
height: 40px;
background: #d6d6d6;
border-radius: 40px;
transition: 1s;
}
input::after{
content: "";
display: block;
transition: 1s;
width: 40px;
height: 40px;
background: white;
border-radius: 50%;
box-shadow: 2px 0 2px rgba(0, 0, 0, 0.363);
}
input:checked{
background: #40d940;
}
input:checked::after{
margin-left: 40px;
box-shadow: -2px 0 2px rgba(0, 0, 0, 0.363);
}
</style>
</head>
<body>
<form>
<input type="checkbox">
</form>
</body>
</html>