style.css
index.html
/* Special selector that means “default”. */
:root {
--font-size: 16px;
--spacing: 20px;
}
@media (min-width: 400px) {
:root {
--font-size: 24px; /* Bump these up. */
--spacing: 40px;
}
}
body {
font-family: sans-serif;
font-size: var(--font-size); /* Use the size. */
padding: var(--spacing); /* Use the spacing. */
}
div {
/* The second value here is a “fallback”. */
/* It’s used if a variable hasn’t been declared. */
background-color: var(--background, aquamarine);
padding: calc(var(--spacing) / 2); /* Calcs, too. */
}
div:not(:first-child) {
--background: gold; /* Only for this element. */
margin-top: var(--spacing);
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/assets/styles/reset.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div>
<p>This element is responsive. I’ll add some text here so we have something to look at and so that it wraps, but the text itself isn’t important, at the moment.</p>
</div>
<div>
<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>
</div>
</body>
</html>