html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Multi-Theme Responsive Layout</title>
<style>
:root {
--color-bg: #f8f9fb;
--color-text: #1a1a1a;
--color-primary: #2563eb;
--color-secondary: #6b7280;
--color-surface: #ffffff;
--color-border: #d1d5db;
--color-accent: #3b82f6;
--shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.dark-theme {
--color-bg: #121212;
--color-text: #e5e7eb;
--color-primary: #3b82f6;
--color-secondary: #9ca3af;
--color-surface: #1e1e1e;
--color-border: #374151;
--color-accent: #60a5fa;
--shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
*, *::before, *::after {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Inter', system-ui, sans-serif;
background-color: var(--color-bg);
color: var(--color-text);
transition: background-color 0.4s ease, color 0.3s ease;
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
background-color: var(--color-surface);
border-bottom: 1px solid var(--color-border);
padding: 1rem 1.5rem;
display: flex;
justify-content: space-between;
align-items: center;
transition: background-color 0.4s ease, border-color 0.3s ease;
}
.logo {
font-weight: 700;
font-size: 1.25rem;
color: var(--color-primary);
}
.theme-switch {
background: none;
border: 2px solid var(--color-primary);
border-radius: 0.375rem;
color: var(--color-primary);
padding: 0.4rem 0.8rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
.theme-switch:hover,
.theme-switch:focus {
background-color: var(--color-primary);
color: var(--color-bg);
outline: none;
}
.container {
display: grid;
grid-template-columns: 1fr 280px;
gap: 1.5rem;
max-width: 1200px;
width: 100%;
padding: 1.5rem;
margin: auto;
flex-grow: 1;
}
main {
display: flex;
flex-direction: column;
gap: 1rem;
}
aside {
background-color: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 0.75rem;
padding: 1rem;
box-shadow: var(--shadow);
transition: background-color 0.4s ease, border-color 0.3s ease;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav li + li {
margin-top: 0.75rem;
}
nav a {
color: var(--color-primary);
text-decoration: none;
font-weight: 600;
transition: color 0.3s ease;
}
nav a:hover,
nav a:focus {
color: var(--color-accent);
outline: none;
}
.card {
background-color: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 1rem;
padding: 1rem 1.5rem;
box-shadow: var(--shadow);
transition: background-color 0.4s ease, border-color 0.3s ease, color 0.3s ease;
}
footer {
background-color: var(--color-surface);
border-top: 1px solid var(--color-border);
padding: 1rem 1.5rem;
text-align: center;
font-size: 0.9rem;
color: var(--color-secondary);
transition: background-color 0.4s ease, border-color 0.3s ease, color 0.3s ease;
}
@media (max-width: 767px) {
.container {
grid-template-columns: 1fr;
padding: 1rem;
}
aside {
order: 2;
}
main {
order: 1;
}
}
</style>
</head>
<body>
<header>
<div class="logo">MyBrand</div>
<button class="theme-switch" aria-label="Toggle theme">Switch Theme</button>
</header>
<div class="container">
<main>
<section class="card">
<h1>Welcome to the Multi-Theme Layout</h1>
<p>This layout responds to different screen sizes and supports a smooth light/dark theme toggle using CSS variable swapping.</p>
</section>
<section class="card">
<h2>Features</h2>
<ul>
<li>Semantic color variables</li>
<li>Responsive CSS Grid layout</li>
<li>Smooth transitions between themes</li>
<li>Accessible toggle button</li>
</ul>
</section>
</main>
<aside>
<nav>
<ul>
<li><a href="#">Overview</a></li>
<li><a href="#">Documentation</a></li>
<li><a href="#">Examples</a></li>
<li><a href="#">Support</a></li>
</ul>
</nav>
</aside>
</div>
<footer>
© 2024 MyBrand. All rights reserved.
</footer>
<script>
const themeSwitch = document.querySelector('.theme-switch');
themeSwitch.addEventListener('click', () => {
document.body.classList.toggle('dark-theme');
});
</script>
</body>
</html>
```</think>
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-theme Responsive Layout</title>
<style>
/* Semantic color tokens */
:root {
--color-bg: #f7f9fb;
--color-surface: #ffffff;
--color-text: #1f2937;
--color-text-muted: #6b7280;
--color-primary: #2563eb;
--color-border: #e5e7eb;
--color-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
/* Dark theme overrides */
.dark-theme {
--color-bg: #0f172a;
--color-surface: #111827;
--color-text: #e5e7eb;
--color-text-muted: #9ca3af;
--color-primary: #60a5fa;
--color-border: #1f2937;
--color-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background-color: var(--color-bg);
color: var(--color-text);
transition: background-color 0.35s ease, color 0.35s ease;
}
header {
position: sticky;
top: 0;
z-index: 10;
backdrop-filter: blur(10px);
background: color-mix(in srgb, var(--color-bg) 85%, transparent);
border-bottom: 1px solid var(--color-border);
transition: background-color 0.35s ease, border-color 0.35s ease;
}
.navbar {
max-width: 1200px;
margin: 0 auto;
padding: 1rem 1.25rem;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.brand {
font-weight: 700;
font-size: 1.1rem;
letter-spacing: 0.03em;
}
.btn {
border: none;
border-radius: 999px;
padding: 0.5rem 1rem;
cursor: pointer;
background: var(--color-primary);
color: #fff;
font-weight: 600;
transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.35s ease;
box-shadow: var(--color-shadow);
}
.btn:hover {
transform: translateY(-1px);
box-shadow: 0 12px 32px rgba(0,0,0,0.12);
}
.container {
max-width: 1200px;
margin: 1.5rem auto;
padding: 0 1.25rem 2.5rem;
display: grid;
grid-template-columns: 2fr 1fr;
gap: 1.25rem;
}
.card {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 14px;
box-shadow: var(--color-shadow);
padding: 1.25rem;
transition: background-color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}
.card h2 {
margin: 0 0 0.35rem;
font-size: 1.25rem;
}
.card p {
margin: 0;
color: var(--color-text-muted);
line-height: 1.6;
}
.tags {
margin: 1rem 0 0;
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.tag {
padding: 0.35rem 0.6rem;
border-radius: 999px;
font-size: 0.85rem;
background: color-mix(in srgb, var(--color-primary) 20%, var(--color-surface));
color: var(--color-primary);
border: 1px solid color-mix(in srgb, var(--color-primary) 30%, var(--color-border));
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1rem;
}
.hero {
grid-column: 1 / -1;
background: linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 50%, transparent) 0%, var(--color-surface) 80%);
}
.sidebar .card + .card {
margin-top: 1rem;
}
footer {
max-width: 1200px;
margin: 0 auto;
padding: 1.5rem 1.25rem;
text-align: center;
color: var(--color-text-muted);
}
/* Responsive */
@media (max-width: 900px) {
.container {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<header>
<div class="navbar">
<div class="brand">MyTheme Layout</div>
<button class="btn" id="theme-toggle">Toggle Theme</button>
</div>
</header>
<main class="container">
<section class="grid">
<article class="card hero">
<h2>Responsive Multi-Theme Layout</h2>
<p>A semantic color system using CSS variables that can be swapped at runtime to enable multiple themes. Try toggling the theme!</p>
<div class="tags">
<span class="tag">Responsive</span>
<span class="tag">CSS Variables</span>
<span class="tag">Dark Mode</span>
</div>
</article>
<article class="card">
<h2>Semantic Tokens</h2>
<p>Define colors by intent—background, surface, text, muted, primary—then override them in a theme scope.</p>
</article>
<article class="card">
<h2>Transitions</h2>
<p>Apply <code>transition: background-color</code> (and <code>color</code>) so switching themes feels smooth.</p>
</article>
<article class="card">
<h2>Responsive Grid</h2>
<p>Use CSS Grid to adapt columns to the viewport. Resize to see the layout stack for smaller screens.</p>
</article>
</section>
<aside class="sidebar">
<div class="card">
<h2>Sidebar Widget</h2>
<p>Cards and other UI pieces inherit the same semantic colors, staying consistent across themes.</p>
</div>
<div class="card">
<h2>Another Widget</h2>
<p>Override once, use everywhere. Variables simplify maintaining multiple themes.</p>
</div>
</aside>
</main>
<footer>
Smooth transitions. Semantic colors. Easy theme swaps.
</footer>
<script>
const toggleButton = document.getElementById('theme-toggle');
toggleButton.addEventListener('click', () => {
document.body.classList.toggle('dark-theme');
});
</script>
</body>
</html>