Skip to content

Commit ae9ac74

Browse files
Dark mode
Enables dark mode support with automatic theme switching based on a users browser theme.
1 parent 4a78684 commit ae9ac74

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

css/main.css

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
body {
2-
background: #f5f5f5;
1+
@media (prefers-color-scheme: light) {
2+
body {
3+
background: #f5f5f5;
4+
}
5+
6+
.drag {
7+
background-color: lightblue;
8+
}
9+
10+
#header {
11+
background: #A0CFFF;
12+
color: #3474A8;
13+
}
14+
15+
.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
16+
background-color: #F5F5E7;
17+
}
318
}
419

5-
.drag {
6-
background-color: lightblue;
7-
}
8-
9-
#header {
10-
background: #A0CFFF;
11-
color: #3474A8;
20+
@media (prefers-color-scheme: dark) {
21+
body {
22+
background: #1a1a1a;
23+
}
24+
25+
.drag {
26+
background-color: #1e3a5f;
27+
}
28+
29+
#header {
30+
background: #0d3b66;
31+
color: #7ab5e6;
32+
}
33+
34+
.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
35+
background-color: #2c2c1e;
36+
}
1237
}
1338

1439
#dropzone {
@@ -24,10 +49,6 @@ body {
2449
opacity: 0;
2550
}
2651

27-
.table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
28-
background-color: #F5F5E7;
29-
}
30-
3152
#data {
3253
margin-bottom: 0;
3354
}

index.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,26 @@
2626
gtag('js', new Date());
2727
gtag('config', 'G-N22SYDVQHZ');
2828
</script>
29+
<script>
30+
const darkModeMediaQuery = window.matchMedia(
31+
"(prefers-color-scheme: dark)",
32+
);
33+
function applyTheme() {
34+
if (darkModeMediaQuery.matches) {
35+
document.documentElement.setAttribute("data-bs-theme","dark");
36+
} else {
37+
document.documentElement.setAttribute("data-bs-theme","light");
38+
}
39+
}
40+
darkModeMediaQuery.addEventListener("change", applyTheme);
41+
applyTheme();
42+
</script>
2943
</head>
3044
<body>
3145

3246
<img src="img/icon.png" style="display: none;"/>
3347

34-
<div id="main-container" class="container shadow bg-white">
48+
<div id="main-container" class="container shadow">
3549
<header id="header" class="row align-items-center p-4">
3650
<img src="img/logo.svg" width="54" height="54" class="col-auto p-0" alt="Database logo"/>
3751

0 commit comments

Comments
 (0)