Skip to content

Commit a4b04d7

Browse files
committed
[css-scoping-1][editorial] Add examples of tree-scoped references and inheritance.
1 parent 02123ba commit a4b04d7

File tree

1 file changed

+110
-1
lines changed

1 file changed

+110
-1
lines changed

css-scoping-1/Overview.bs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,115 @@ Name-Defining Constructs and Inheritance</h3>
608608
* others?
609609
</div>
610610

611+
<div class=example>
612+
613+
For example,
614+
given the following document
615+
(using the imaginary <::shadow></::shadow> markup
616+
to indicate an element's [=shadow tree=]):
617+
618+
<xmp highlight=markup>
619+
<p class=outer>Here's some text in the outer document's "foo" font.
620+
<style>
621+
@font-face {
622+
font-family: foo;
623+
src: url(https://example.com/outer.woff);
624+
}
625+
body { font-family: foo; }
626+
my-component::part(text) { font-family: foo; }
627+
</style>
628+
629+
<my-component>
630+
<::shadow>
631+
<p class=inner-default>I'm inheriting the outer document's font-family.
632+
<p class=inner-styled>And I'm explicitly styled to be in the component's "foo" font.
633+
<p class=part-styled part=text>
634+
I'm explicitly styled by the outer document,
635+
and get the outer document's "foo" font.
636+
<style>
637+
@font-face {
638+
font-family: foo;
639+
src: url(https://example.com/inner.woff);
640+
}
641+
.inner-styled { font-family: foo; }
642+
</style>
643+
</::shadow>
644+
</my-component>
645+
</xmp>
646+
647+
The ''.outer'' element references the outer ''@font-face'', using the "outer.woff" file.
648+
649+
The ''.inner-default'' element inherits the ''font-family: foo'' value from the outer document,
650+
using the same [=tree-scoped reference=] as ''.outer'',
651+
and thus also uses the "outer.woff" font file.
652+
653+
The ''.inner-style'' element, on the other hand,
654+
receives a ''font-family: foo'' from the stylesheet inside the shadow,
655+
and thus its [=tree-scoped reference=] refers to the shadow's ''@font-family'',
656+
and it uses the "inner.woff" file.
657+
658+
The ''.part-styled'' element also receives its style from the outer document,
659+
tho by being directly set rather than by inheritance.
660+
Thus, its [=tree-scoped reference=] also refer's to the outer document,
661+
and it uses the "outer.woff" file.
662+
</div>
663+
664+
<div class=example>
665+
Here is a more complex example,
666+
showing three levels of trees,
667+
and illustrating precisely how [=tree-scoped names=] and [=tree-scoped references=] inherit.
668+
669+
<xmp highlight=markup>
670+
<style>
671+
@font-face {
672+
font-family: foo;
673+
src: url(https://example.com/outer.woff);
674+
}
675+
body { font-family: foo; }
676+
</style>
677+
678+
<child-component>
679+
<::shadow>
680+
<style>
681+
@font-face {
682+
font-family: foo;
683+
src: url(https://example.com/inner.woff);
684+
}
685+
</style>
686+
687+
<grandchild-component>
688+
<::shadow>
689+
<p class=inner-default>
690+
I'm inheriting the outer document's "foo" font.
691+
</p>
692+
<p class=inner-search>
693+
And I can't find a local "foo" font,
694+
so I'm searching further up the tree,
695+
and find the shadow's "foo" font.
696+
</p>
697+
<style>
698+
.inner-search { font-family: foo; }
699+
</style>
700+
</::shadow>
701+
</grandchild-component>
702+
</::shadow>
703+
</child-component>
704+
</xmp>
705+
706+
Here, just as in the previous example,
707+
''.inner-default'' is inheriting the ''font-family: foo'' declared in the outer document,
708+
and so it ends up referencing the outer document's ''@font-face'',
709+
and is rendered with the "outer.woff" file.
710+
711+
On the other hand,
712+
''.inner-search'' recieves its style from a stylesheet in <code>&lt;grandchild-component></code>'s shadow tree,
713+
so it attempts to find a ''@font-face'' defining a ''foo'' font in that tree.
714+
There is no such ''@font-face'',
715+
so it starts walking up the shadow trees,
716+
finding an appropriate ''@font-face'' in <code>&lt;child-component></code>,
717+
so it's rendered with the "inner.woff" file.
718+
</div>
719+
611720
<h4 id='shadow-names-serialization'>
612721
Serialized Tree-Scoped References</h4>
613722

@@ -633,7 +742,7 @@ Serialized Tree-Scoped References</h4>
633742
font-family: foo;
634743
src: url(foo.woff);
635744
}
636-
.outer { font-family: foo; }
745+
body { font-family: foo; }
637746
</style>
638747

639748
<my-component>

0 commit comments

Comments
 (0)