-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdarkmode.html
More file actions
52 lines (46 loc) · 1.52 KB
/
darkmode.html
File metadata and controls
52 lines (46 loc) · 1.52 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detecção automática do tema do sistema</title>
<style>
body {
font-family: Arial, sans-serif;
transition: background-color 0.3s, color 0.3s;
}
.dark-mode {
background-color: #333;
color: #fff;
}
.light-mode {
background-color: #fff;
color: #333;
}
@media(max-width: 768px)
{
body{
background-color: red;
}
}
</style>
</head>
<body>
<h1>Detecção automática do tema do sistema</h1>
<p>Este é um exemplo de página web que ajusta automaticamente seu tema com base nas preferências de cores do sistema operacional do usuário.</p>
<script>
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
function setTheme() {
if (prefersDarkScheme.matches) {
document.body.classList.remove('light-mode');
document.body.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
document.body.classList.add('light-mode');
}
}
setTheme(); // Configura o tema na carga inicial da página
prefersDarkScheme.addListener(setTheme); // Atualiza o tema quando as preferências do sistema mudam
</script>
</body>
</html>