-
Notifications
You must be signed in to change notification settings - Fork 0
/
dark-mode.css
188 lines (168 loc) · 5.54 KB
/
dark-mode.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
# Dark Mode Toggle Stylesheet
#
# Author:
# Name: Marco Steinbrecher
# Email: dtm@steinbrecher.co
# GitHub: https://github.com/MacSteini/dark-mode-toggle
#
# Styles for light and dark themes with smooth transitions. Includes:
# - Theme variables for customisation
# - Tooltips for accessibility and dynamic positioning
# - Mobile-friendly adjustments
#
# Features:
# - Theme-specific styles for backgrounds, text, links, and tooltips
# - Responsive scaling for icons and tooltips
# - RTL support
#
# MIT Licence applies. See GitHub for details.
*/
/* Hidden Class */
/* Ensures elements are hidden until JavaScript enables them */
.hidden {
display: none;
}
/* Theme Variables */
/* Define color variables for light and dark themes */
:root {
/* Light Theme Variables */
--bg-color: #fff; /* Background color for light theme */
--text-color: #000; /* Text color for light theme */
--article-bg: #f9f9f9; /* Article background for light theme */
--article-text: #333; /* Article text for light theme */
--link-color: #1a0dab; /* Link color for light theme */
--tooltip-bg: #333; /* Tooltip background for light theme */
--tooltip-color: #f39c12; /* Tooltip text color for light theme */
}
[data-theme="dark"] {
/* Dark Theme Variables */
--bg-color: #121212; /* Background color for dark theme */
--text-color: #fff; /* Text color for dark theme */
--article-bg: #1e1e1e; /* Article background for dark theme */
--article-text: #ccc; /* Article text for dark theme */
--link-color: #8ab4f8; /* Link color for dark theme */
--tooltip-bg: #fff; /* Tooltip background for dark theme */
--tooltip-color: #6495ed; /* Tooltip text color for dark theme */
}
/* Base Styles */
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
transition: background-color 0.3s ease-in-out, color 0.3s ease-in-out; /* Smooth theme transitions */
}
article {
background-color: var(--article-bg);
color: var(--article-text);
padding: 1.5rem;
margin: 1rem auto;
max-width: 80rem;
border-radius: 0.8rem; /* Rounded corners for articles */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */
transition: background-color 0.3s ease-in-out, color 0.3s ease-in-out; /* Smooth transitions */
}
article a {
color: var(--link-color); /* Link color defined by theme variables */
text-decoration: none;
transition: color 0.3s ease-in-out; /* Smooth link color transitions */
}
article a:hover {
text-decoration: underline; /* Underline on hover for better UX */
}
/* Dark Mode Toggle Styles */
.dark-mode-toggle {
font-size: clamp(2rem, 1vw, 3rem); /* Dynamically resize for responsiveness */
padding: 0.5rem;
border: none;
background: none;
background-color: transparent; /* Ensure no background flashes */
color: var(--text-color); /* Adjusts with theme */
position: fixed;
top: 1rem;
right: 1rem;
z-index: 999;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
transition: color 0.3s ease-in-out, background-color 0.3s ease-in-out;
}
.dark-mode-toggle:focus-visible {
outline: 2px solid var(--tooltip-color); /* Provide visible focus for accessibility */
outline-offset: 4px;
}
.dark-mode-toggle:active {
background-color: transparent; /* Avoid background flashes on active state */
}
/* Tooltip Styles */
.dark-mode-toggle::after {
content: attr(aria-label);
position: absolute;
top: 150%;
transform: translateX(-50%);
background-color: var(--tooltip-bg);
color: var(--tooltip-color);
font-size: clamp(0.7rem, 1vw, 1rem); /* Consistent tooltip size */
padding: 0.4rem 0.8rem;
border: 0.3rem solid var(--tooltip-color);
border-radius: 0.4rem;
opacity: 0;
white-space: nowrap; /* Prevent tooltip wrapping */
pointer-events: none;
transition: opacity 0.3s ease-in-out, top 0.3s ease-in-out;
z-index: 1000; /* Ensure tooltip appears above other elements */
}
.dark-mode-toggle:hover::after,
.dark-mode-toggle:focus::after {
opacity: 1; /* Make tooltip visible on hover and focus */
top: 100%; /* Slide tooltip upward */
}
/* Touch Device Adjustments */
@media (hover: none) and (pointer: coarse) {
.dark-mode-toggle {
background-color: transparent; /* Reset background for touch devices */
}
.dark-mode-toggle:focus {
outline: none; /* Remove focus outlines on touch */
box-shadow: none; /* Suppress visual artifacts */
}
.dark-mode-toggle::after {
display: none; /* Disable tooltips on touch devices */
}
}
/* Icon Styles */
.dark-mode-toggle i {
border-radius: 50%; /* Circular background */
padding: 0.2em;
width: 1em;
height: 1em;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.3s ease-in-out, color 0.3s ease-in-out,
background-color 0.3s ease-in-out;
border: 0.2rem solid var(--tooltip-color); /* Match tooltip border color */
}
/* Light and Dark Theme Icons */
[data-theme="light"] .dark-mode-toggle i {
color: var(--tooltip-color); /* Sun icon color for light theme */
background-color: var(--tooltip-bg); /* Dark circle for light theme */
}
[data-theme="dark"] .dark-mode-toggle i {
transform: rotate(360deg); /* Rotation effect */
color: var(--tooltip-color); /* Moon icon color for dark theme */
background-color: var(--tooltip-bg); /* Light circle for dark theme */
}
/* RTL Support */
[dir="rtl"] .dark-mode-toggle {
right: auto; /* Align to left for RTL */
left: 1rem;
}
[dir="rtl"] .dark-mode-toggle::after {
left: auto; /* Adjust tooltip alignment for RTL */
right: 50%;
transform: translateX(50%);
}