<main class="light">
<header>
<h1>Scope Demo 3: Child Elements</h1>
<button>light-mode button</button>
</header>
<section class="dark">
<h2>Nested "Dark Mode"</h2>
<button>dark-mode button</button>
</section>
</main>
.dark {
--btn-color: plum;
--btn-contrast: black;
background: black;
color: white;
}
.light {
--btn-color: rebeccapurple;
--btn-contrast: white;
background: white;
color: black;
}
button {
background: var(--btn-color, rebeccapurple);
color: var(--btn-contrast, white);
}
/* layout */
*, *::before, *::after {
box-sizing: border-box;
}
html {
font-family: avenir, roboto, helvetica, sans-serif;
}
main {
font-size: calc(1em + 0.5vw);
display: grid;
min-height: 100vh;
place-content: safe center;
padding: 1em;
}
header,
section {
padding: 1em;
}
section section {
margin-top: 1em;
}
h1, h2, h3 {
margin-top: 0;
}
button {
border: none;
border-radius: 0.25em;
padding: 0.25em 1.5em;
font: inherit;
cursor: pointer;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.