You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [css-variables] Handle short-circuiting var(), argument grammars, etc
The main part of the cycle behavior is now specified in css-values,
so css-variables does not really need that much on that topic anymore.
This should mostly bring css-variables-1/2 up to date with #11500.
* Update css-variables-1/Overview.bs
---------
Co-authored-by: Anders Hartvoll Ruud <andruud@google.com>
Co-authored-by: Tab Atkins Jr. <jackalmage@gmail.com>
(along with any other properties that use ''var(--main-color)'')
576
-
will automatically update when the '--main-color' property is changed.
577
-
</div>
578
-
579
-
<div class='example invalid-example'>
580
-
On the other hand,
581
-
this example shows an invalid instance of variables depending on each other:
582
-
583
-
<pre>
584
-
:root {
585
-
--one: calc(var(--two) + 20px);
586
-
--two: calc(var(--one) - 20px);
587
-
}
588
-
</pre>
589
-
590
-
Both '--one' and '--two' are now [=invalid at computed-value time=],
591
-
and compute to the [=guaranteed-invalid value=]
592
-
rather than lengths.
593
-
</div>
594
-
595
-
It is important to note that
596
-
<a>custom properties</a> resolve any ''var()'' functions in their values at computed-value time,
597
-
which occurs <em>before</em> the value is inherited.
598
-
In general,
599
-
cyclic dependencies occur only when multiple custom properties on the same element refer to each other;
600
-
custom properties defined on elements higher in the element tree can never cause a cyclic reference with properties defined on elements lower in the element tree.
601
-
602
-
<wpt>
603
-
variable-declaration-51.html
604
-
variable-declaration-52.html
605
-
</wpt>
606
-
607
-
<div class='example'>
608
-
For example,
609
-
given the following structure,
610
-
these custom properties are <strong>not</strong> cyclic,
611
-
and all define valid variables:
612
-
613
-
<xmp highlight=markup>
614
-
<one><two><three /></two></one>
615
-
<style>
616
-
one { --foo: 10px; }
617
-
two { --bar: calc(var(--foo) + 10px); }
618
-
three { --foo: calc(var(--bar) + 10px); }
619
-
</style>
620
-
</xmp>
621
-
622
-
The <one> element defines a value for '--foo'.
623
-
The <two> element inherits this value,
624
-
and additionally assigns a value to '--bar' using the ''foo'' variable.
625
-
Finally,
626
-
the <three> element inherits the '--bar' value
627
-
<em>after</em> variable substitution
628
-
(in other words, it sees the value ''calc(10px + 10px)''),
629
-
and then redefines '--foo' in terms of that value.
630
-
Since the value it inherited for '--bar' no longer contains a reference to the '--foo' property defined on <one>,
631
-
defining '--foo' using the ''var(--bar)'' variable is not cyclic,
632
-
and actually defines a value that will eventually
633
-
(when referenced as a variable in a normal property)
634
-
resolve to ''30px''.
635
-
</div>
636
-
637
-
638
512
<!-- Big Text: var()
639
513
640
514
█▌ █▌ ███▌ ████▌ ██ ██
@@ -658,7 +532,12 @@ Using Cascading Variables: the ''var()'' notation</h2>
0 commit comments