Skip to content

Commit 1a8dccc

Browse files
committed
[css-variables] Move examples to more appropriate places. Fixes w3c#462.
1 parent 604f4bd commit 1a8dccc

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

css-variables/Overview.bs

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Previous Version: https://www.w3.org/TR/2013/WD-css-variables-20130312/
1515
Previous Version: https://www.w3.org/TR/2012/WD-css-variables-20120410/
1616
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact
1717
Abstract: This module introduces cascading variables as a new primitive value type that is accepted by all CSS properties, and custom properties for defining them.
18+
Default Highlight: css
1819
</pre>
1920

2021
<pre class=link-defaults>
@@ -239,11 +240,11 @@ Custom Property Value Syntax</h3>
239240
#alert { --color: red; }
240241
* { color: var(--color); }
241242

242-
&lt;p>I inherited blue from the root element!&lt;/p>
243-
&lt;div>I got green set directly on me!&lt;/div>
243+
&lt;p><span style="color: blue">I inherited blue from the root element!</span>&lt;/p>
244+
&lt;div><span style="color: green">I got green set directly on me!</span>&lt;/div>
244245
&lt;div id='alert'>
245-
While I got red set directly on me!
246-
&lt;p>I'm red too, because of inheritance!&lt;/p>
246+
<span style="color: red">While I got red set directly on me!</span>
247+
&lt;p><span style="color: red">I'm red too, because of inheritance!</span>&lt;/p>
247248
&lt;/div>
248249
</pre>
249250
</div>
@@ -401,6 +402,21 @@ Using Cascading Variables: the ''var()'' notation</h2>
401402
(Doing so usually produces invalid syntax,
402403
or else a value whose meaning has no connection to the variable.)
403404

405+
<div class='example'>
406+
For example, the following code incorrectly attempts to use a variable as a property name:
407+
408+
<pre>
409+
.foo {
410+
--side: margin-top;
411+
var(--side): 20px;
412+
}
413+
</pre>
414+
415+
This is <em>not</em> equivalent to setting ''margin-top: 20px;''.
416+
Instead, the second declaration is simply thrown away as a syntax error
417+
for having an invalid property name.
418+
</div>
419+
404420
The first argument to the function is the name of the <a>custom property</a> to be substituted.
405421
The second argument to the function, if provided,
406422
is a fallback value,
@@ -410,38 +426,6 @@ Using Cascading Variables: the ''var()'' notation</h2>
410426
For example, ''var(--foo, red, blue)'' defines a fallback of ''red, blue'';
411427
that is, anything between the first comma and the end of the function is considered a fallback value.
412428

413-
If a property contains one or more ''var()'' functions,
414-
and those functions are syntactically valid,
415-
the entire property's grammar must be assumed to be valid at parse time.
416-
It is only syntax-checked at computed-value time,
417-
after ''var()'' functions have been <a lt="substitute a var()">substituted</a>.
418-
419-
To <dfn export>substitute a var()</dfn> in a property's value:
420-
421-
<ol>
422-
<li>
423-
If the <a>custom property</a> named by the first argument to the ''var()'' function is <a>animation-tainted</a>,
424-
and the ''var()'' function is being used in the 'animation' property or one of its longhands,
425-
treat the <a>custom property</a> as having its initial value for the rest of this algorithm.
426-
427-
<li>
428-
If the value of the <a>custom property</a> named by the first argument to the ''var()'' function
429-
is anything but the initial value,
430-
replace the ''var()'' function by the value of the corresponding <a>custom property</a>.
431-
432-
<li>
433-
Otherwise, if the ''var()'' function has a fallback value as its second argument,
434-
replace the ''var()'' function by the fallback value.
435-
If there are any ''var()'' references in the fallback,
436-
<a lt="substitute a var()">substitute</a> them as well.
437-
438-
<li>
439-
Otherwise,
440-
the property containing the ''var()'' function is <a>invalid at computed-value time</a>.
441-
442-
Note: Other things can also make a property <a>invalid at computed-value time</a>.
443-
</ol>
444-
445429
<div class='example'>
446430
The fallback value allows for some types of defensive coding.
447431
For example,
@@ -475,21 +459,42 @@ Using Cascading Variables: the ''var()'' notation</h2>
475459
</pre>
476460
</div>
477461

478-
<div class='example'>
479-
For example, the following code incorrectly attempts to use a variable as a property name:
462+
If a property contains one or more ''var()'' functions,
463+
and those functions are syntactically valid,
464+
the entire property's grammar must be assumed to be valid at parse time.
465+
It is only syntax-checked at computed-value time,
466+
after ''var()'' functions have been <a lt="substitute a var()">substituted</a>.
480467

481-
<pre>
482-
.foo {
483-
--side: margin-top;
484-
var(--side): 20px;
485-
}
486-
</pre>
468+
To <dfn export lt="substitute a var()|var() substitution">substitute a var()</dfn> in a property's value:
487469

488-
This is <em>not</em> equivalent to setting ''margin-top: 20px;''.
489-
Instead, the second declaration is simply thrown away as a syntax error
490-
for having an invalid property name.
470+
<ol>
471+
<li>
472+
If the <a>custom property</a> named by the first argument to the ''var()'' function is <a>animation-tainted</a>,
473+
and the ''var()'' function is being used in the 'animation' property or one of its longhands,
474+
treat the <a>custom property</a> as having its initial value for the rest of this algorithm.
475+
476+
<li>
477+
If the value of the <a>custom property</a> named by the first argument to the ''var()'' function
478+
is anything but the initial value,
479+
replace the ''var()'' function by the value of the corresponding <a>custom property</a>.
480+
481+
<li>
482+
Otherwise, if the ''var()'' function has a fallback value as its second argument,
483+
replace the ''var()'' function by the fallback value.
484+
If there are any ''var()'' references in the fallback,
485+
<a lt="substitute a var()">substitute</a> them as well.
486+
487+
<li>
488+
Otherwise,
489+
the property containing the ''var()'' function is <a>invalid at computed-value time</a>.
490+
491+
Note: Other things can also make a property <a>invalid at computed-value time</a>.
492+
</ol>
491493

492-
Similarly, you can't build up a single token where part of it is provided by a variable:
494+
<div class=note>
495+
Note that <a>var() substitution</a> takes place at the level of CSS tokens [[css-syntax-3]],
496+
not at a textual level;
497+
you can't build up a single token where part of it is provided by a variable:
493498

494499
<pre>
495500
.foo {
@@ -498,7 +503,7 @@ Using Cascading Variables: the ''var()'' notation</h2>
498503
}
499504
</pre>
500505

501-
Again, this is <em>not</em> equivalent to setting ''margin-top: 20px;'' (a length).
506+
This is <em>not</em> equivalent to setting ''margin-top: 20px;'' (a length).
502507
Instead, it's equivalent to ''margin-top: 20 px;'' (a number followed by an ident),
503508
which is simply an invalid value for the 'margin-top' property.
504509
Note, though, that ''calc()'' can be used to validly achieve the same thing, like so:

0 commit comments

Comments
 (0)