Skip to content

Commit f1eac86

Browse files
committed
Use direct color values with !important to override external CSS
The previous approach relied on CSS variables that were being overridden by the external client.css file. Now using hard-coded color values applied directly to elements with !important to ensure they take precedence. Changes: - Apply colors directly to html, body, and * selectors (not via variables) - Use !important to override any conflicting external CSS rules - Dark mode default: white text (#f5f9ff) on dark bg (#0a0e1f) - Light mode: dark text (#0a0e1f) on light bg (#e7f4f5) - Keep CSS variables for backward compatibility with external CSS This ensures text is visible regardless of external CSS load timing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0d69d7a commit f1eac86

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

website/src/components/code-preview.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function generateJavaScriptIFrameHTML(
1717
<meta charset="utf-8">
1818
<meta name="viewport" content="width=device-width,initial-scale=1">
1919
<script>
20-
// Detect and apply color scheme before any rendering
20+
// Detect and apply color scheme immediately
2121
const colorScheme = sessionStorage.getItem("color-scheme") ||
2222
(
2323
window.matchMedia &&
@@ -26,40 +26,46 @@ function generateJavaScriptIFrameHTML(
2626
: "light"
2727
);
2828
29-
// Set colors directly on html element
30-
const isDark = colorScheme === "dark";
31-
const bgColor = isDark ? "#0a0e1f" : "#e7f4f5";
32-
const textColor = isDark ? "#f5f9ff" : "#0a0e1f";
33-
34-
document.documentElement.style.setProperty("--bg-color", bgColor);
35-
document.documentElement.style.setProperty("--text-color", textColor);
36-
37-
if (!isDark) {
29+
if (colorScheme !== "dark") {
3830
document.documentElement.classList.add("color-scheme-light");
3931
}
4032
</script>
4133
<style>
42-
/* Inline styles to ensure text is visible */
34+
/* Dark mode (default) - apply colors directly without variables */
35+
html, body {
36+
background-color: #0a0e1f !important;
37+
color: #f5f9ff !important;
38+
margin: 0;
39+
padding: 0;
40+
}
41+
* {
42+
color: #f5f9ff !important;
43+
box-sizing: border-box;
44+
}
45+
46+
/* Light mode overrides */
47+
html.color-scheme-light, html.color-scheme-light body {
48+
background-color: #e7f4f5 !important;
49+
color: #0a0e1f !important;
50+
}
51+
html.color-scheme-light * {
52+
color: #0a0e1f !important;
53+
}
54+
55+
/* CSS variables for compatibility with external CSS */
4356
:root {
4457
--bg-color: #0a0e1f;
4558
--text-color: #f5f9ff;
46-
color: var(--text-color);
47-
background-color: var(--bg-color);
59+
--highlight-color: #daa520;
4860
}
4961
.color-scheme-light {
5062
--bg-color: #e7f4f5;
5163
--text-color: #0a0e1f;
64+
--highlight-color: #daa520;
5265
}
53-
* {
54-
color: inherit;
55-
box-sizing: border-box;
56-
}
66+
5767
body {
58-
background-color: var(--bg-color);
59-
color: var(--text-color);
6068
font-family: sans-serif;
61-
margin: 0;
62-
padding: 0;
6369
}
6470
</style>
6571
<link

0 commit comments

Comments
 (0)