-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom switch.css
79 lines (73 loc) · 2.54 KB
/
custom switch.css
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
:root {
/*height of the inside square/circle*/
--switch-size:26px;
/*padding between the switch and the inside square/circle*/
--switch-padding:4px;
/*the time it takes for the switch to play the animation*/
--switch-transition:.4s;
/*shadow on the inside of the switch when hovered*/
--switch-shadow:0 0 4px #0006;
/*color of the switch when unchecked*/
--switch-basecolor: #ccc;
/*color of the switch when checked*/
--switch-checkedcolor: #2196F3;
/*color of the inside square/circle*/
--switch-slidercolor: white;
/*how round the switches with class="round" should be
1 = circle, 0 = square*/
--switch-roundness: 1;
}
/*make the switch inline*/
.switch {
display: inline-block;
}
/*make the switches with class="round" round*/
.switch.round > .outer, .switch.round > .outer > .inner {
border-radius: calc((var(--switch-size)/2 + var(--switch-padding))*var(--switch-roundness));
}
/*set shadow to show when the switch is hovered*/
.switch:hover > .outer > .inner{
box-shadow: var(--switch-shadow);
}
.switch:hover > .outer{
box-shadow: inset var(--switch-shadow);
}
/*settings for the outer part of the switch*/
.switch > .outer {
/*behave consistently with padding*/
box-sizing: border-box!important;
/*background color for when the switch is off*/
background-color: var(--switch-basecolor);
/*make it twice as wide (+padding) as the inner part*/
width: calc(var(--switch-size)*2 + var(--switch-padding)*2); height: calc(var(--switch-size)+var(--switch-padding)*2);
padding: var(--switch-padding);
/*set animation*/
-webkit-transition: var(--switch-transition);
transition: var(--switch-transition);
}
.switch > input:checked + .outer{
/*background color for when the switch is on*/
background-color: var(--switch-checkedcolor);
}
/*settings for the inner part of the switch*/
.switch > .outer > .inner {
/*set color*/
background-color: var(--switch-slidercolor);
/*set size*/
height: var(--switch-size);
width: var(--switch-size);
/*ste animation*/
-webkit-transition: var(--switch-transition);
transition: var(--switch-transition);
}
/*move the inner part when the switch is on*/
.switch > input:checked + .outer >.inner {
-webkit-transform: translateX(100%);
-ms-transform: translateX(100%);
transform: translateX(100%);
}
/*make the actual checkbox invisible*/
.switch > input {
width:0;height:0;
opacity: 0;float: left;
}