-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_dark_mode.html
More file actions
65 lines (56 loc) · 1.24 KB
/
toggle_dark_mode.html
File metadata and controls
65 lines (56 loc) · 1.24 KB
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
<label class="theme-toggle">
<input type="checkbox" id="darkModeToggle">
<span class="slider"></span>
</label>
<style>
:root {
--bg-color: white;
--text-color: black;
}
body {
background: var(--bg-color);
color: var(--text-color);
transition: 0.3s;
}
.theme-toggle {
position: fixed;
top: 20px;
right: 20px;
width: 50px;
height: 25px;
}
.theme-toggle input {
display: none;
}
.slider {
position: absolute;
width: 100%;
height: 100%;
background: #ddd;
border-radius: 25px;
transition: 0.3s;
}
.slider::before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
top: 50%;
left: 4px;
transform: translateY(-50%);
transition: 0.3s;
}
.theme-toggle input:checked+.slider {
background: black;
}
.theme-toggle input:checked+.slider::before {
transform: translate(25px, -50%);
background: yellow;
}
.theme-toggle input:checked~body {
--bg-color: black;
--text-color: white;
}
</style>