<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/assets/reset.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<section>
<p>This element is responsive.</p>
<p>I’ll add some text more here so we have something to look at and so that it wraps, but the text itself isn’t important, at the moment.</p>
</section>
<section>
<p>This is another responsive element, with some more text in it. Again the text doesn’t really matter, I just want a bit of stuff in here. A few lines, is all.</p>
</section>
</body>
</html>
/* Special selector that means “default” / `html`. */
:root {
--spacing: 1rem;
font-size: 100%;
}
@media (width > 550px) {
:root {
--spacing: 2rem;
font-size: 125%; /* Bumps everything up. */
}
}
body {
font-family: sans-serif;
font-size: 1rem; /* Reference the size, as you have been. */
padding: var(--spacing); /* Or use a spacing variable. */
}
section {
/* The second value here is a “fallback”. */
/* It’s used if a variable hasn’t been declared. */
background-color: var(--background, aquamarine);
padding: var(--spacing);
}
section:not(:first-child) {
--background: gold; /* Only within this element. */
/* You can use `calc` on number variables, too! */
margin-block-start: calc(var(--spacing) * 2);
}