-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios-checkbox.html
85 lines (73 loc) · 1.51 KB
/
ios-checkbox.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ios-checkbox.html</title>
<style>
/*第一种方法:伪元素*/
label.alpha{
display: inline-block;
width: 100px;
height: 50px;
background-color:#dddddd;
border:1px solid #dddddd;
border-radius: 51px;
}
input.first:checked + label.alpha{
background-color:#6edd5e;
}
input.first:checked + label.alpha::before{
left: 50%;
}
label.alpha::before{
position: relative;
content: "";
display: block;
width:50%;
height: 100%;
background-color: white;
border:1px solid #dddddd;
border-radius: 51px;
}
/*第二种方法:改变元素位置*/
label.beta{
position:absolute;
display:inline-block;
width: 100px;
height: 50px;
background-color: #dddddd;
border-radius: 50px;
xtransition: 1s;
}
span{
display:inline-block;
width: 50px;
height: 50px;
xright:0;
left: 0;
background-color: white;
border-radius: 50px;
position:relative;
transition:0.5s
}
input.second:checked + label.beta{
background-color:#6edd5e
}
input.second:checked + label.beta span{
position:relative;
xright: -50px;
left:50px;
transition: 0.5s;
}
</style>
</head>
<body>
<input class="first" type="checkbox" id="iOSbutton" hidden="">
<label class="alpha" for="iOSbutton"></label>
<hr>
<input class="second" type="checkbox" id="one" hidden="" >
<label class="beta" for="one">
<span></span>
</label>
</body>
</html>