Skip to content

Commit 0cf77c6

Browse files
committed
[css-variables] Add an example of valid variable usage right in the beginning, per jdaggett's recommendation.
1 parent dc80508 commit 0cf77c6

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

css-variables/Overview.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,27 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Custom
308308
authors and users; CSS will never give them a meaning beyond what is
309309
presented here.
310310

311+
<div class=example> Custom properties define variables, which can be used
312+
for many purposes. For example, a page that consistently uses a small set
313+
of colors in its design can store the colors in custom properties and use
314+
them with variables:
315+
<pre>:root {
316+
main-color: #06c;
317+
accent-color: #006;
318+
}
319+
/* The rest of the CSS file */
320+
#foo h1 {
321+
color: var(main-color);
322+
}
323+
</pre>
324+
325+
<p> The naming provides a mnemonic for the colors, prevents
326+
difficult-to-spot typos in the color codes, and if the theme colors are
327+
ever changed, focuses the change on one simple spot (the custom property
328+
value) rather than requiring tons of edits across all stylesheets in the
329+
project.
330+
</div>
331+
311332
<p> Unlike other CSS properties, custom properties are
312333
<strong>case-sensitive</strong>. The "var-" prefix <strong>must</strong>
313334
be written in lower-case.

css-variables/Overview.src.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ <h2 id='defining-variables'>
7878
<i>Custom properties</i> are solely for use by authors and users;
7979
CSS will never give them a meaning beyond what is presented here.
8080

81+
<div class='example'>
82+
Custom properties define variables,
83+
which can be used for many purposes.
84+
For example, a page that consistently uses a small set of colors in its design
85+
can store the colors in custom properties
86+
and use them with variables:
87+
88+
<pre>
89+
:root {
90+
main-color: #06c;
91+
accent-color: #006;
92+
}
93+
/* The rest of the CSS file */
94+
#foo h1 {
95+
color: var(main-color);
96+
}
97+
</pre>
98+
99+
The naming provides a mnemonic for the colors,
100+
prevents difficult-to-spot typos in the color codes,
101+
and if the theme colors are ever changed,
102+
focuses the change on one simple spot
103+
(the custom property value)
104+
rather than requiring tons of edits across all stylesheets in the project.
105+
</div>
106+
81107
Unlike other CSS properties,
82108
custom properties are <strong>case-sensitive</strong>.
83109
The "var-" prefix <strong>must</strong> be written in lower-case.

0 commit comments

Comments
 (0)