-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
767 lines (615 loc) · 27.3 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
<h1>CSS Scoping Module Level 1</h1>
<pre class='metadata'>
Level: 1
Shortname: css-scoping
Group: CSSWG
Status: ED
Work Status: Exploring
TR: http://www.w3.org/TR/css-scoping-1/
ED: http://dev.w3.org/csswg/css-scoping/
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Editor: Elika J Etemad, Invited Expert, http://fantasai.inkedblade.net/contact
Abstract: This specification defines various scoping/encapsulation mechanisms for CSS, including scoped styles and the ''@scope'' rule, Shadow DOM selectors, and page/region-based styling.
Ignored Terms: content, shadowroot, scoped
Link Defaults: selectors (dfn) child combinator, html (element) style
Issue Tracking: Bugzilla https://www.w3.org/Bugs/Public/buglist.cgi?component=Scoping&list_id=47685&product=CSS&resolution=---
</pre>
<h2 id="intro">
Introduction</h2>
...
<h2 id='scope'>
Scoped Styles</h2>
<a>Scoped</a> style rules apply only within a subtree of a document,
rather than matching against the entire document.
Scoping has two primary effects:
* The selector of the <a>scoped</a> style rule is restricted to match only elements within scope.
See <a href="http://www.w3.org/TR/selectors4/#scoping">Scoped Selectors</a> in [[SELECTORS4]].
* The cascade prioritizes scoped rules over unscoped ones, regardless of specificity.
See <a href="http://www.w3.org/TR/css-cascade/#cascade-scope">Cascading by Scope</a> in [[CSS3CASCADE]].
<h3 id='scoping-mechanisms'>
Scoping Mechanisms</h3>
Style rules can be scoped using constructs defined in the document language
or using the ''@scope'' rule in CSS.
“Scoping” consists of three somewhat independent concepts,
which are in practice generally used together:
* A declaration can be scoped to a <a>scoping root</a>,
which <a href="http://dev.w3.org/csswg/css-cascade/#cascade-scope">affects its cascading behavior</a>. [[!CSS3CASCADE]]
(Alternately, a style rule can be scoped to a <a>scoping root</a>,
which scopes all of the declarations it contains to that <a>scoping root</a>.)
* A selector can be either <a>scope-contained</a> or <a>scope-filtered</a> to a <a>scoping root</a>,
which <a href="http://dev.w3.org/csswg/selectors/#evaluating-selectors">limits what elements it is allowed to match</a>. [[!SELECTORS4]]
* The '':scope'' pseudo-class matches whatever the context sets as the <a>:scope elements</a>,
and is used by several features, such as relative selectors.
In the absence of any anything explicitly setting the <a>:scope elements</a> to something,
the '':scope'' pseudo-class matches the selector's <a>scoping root</a>.
<h4 id='scoping-markup'>
Document Markup for Scoping</h4>
Document languages may define a mechanism for a stylesheet to be scoped to some element in the document.
For example, in HTML,
a <a element>style</a> element with a <a element-attr for="style">scoped</a> attribute
defines a stylesheet that is scoped to the <a element>style</a> element’s parent element.
[[HTML]]
The element that the stylesheet is scoped to
is the <a>scoping root</a> for all the style rules in the stylesheet,
and selectors of style rules in the stylesheet
are <a>scope-contained</a> to the <a>scoping root</a>.
<h4 id='scope-atrule'>
CSS Syntax for Scoping: the ''@scope'' rule</h4>
The <dfn>@scope</dfn> at-rule allows authors to create scoped style rules using CSS syntax.
The syntax of the ''@scope'' rule is:
<pre class='prod'>
@scope <<selector>> {
<<stylesheet>>
}
</pre>
where the elements matched by the <<selector>>
are <a>scoping roots</a> for the style rules in <<stylesheet>>,
and selectors of style rules scoped by ''@scope'' are
<a>scope-contained</a> to their <a>scoping root</a>.
<p class="issue">
This rule makes it very easy for authors to create scoped style sheets,
which could affect the optimization strategies for implementing scoped styles.
If multiple elements match the <<selector>>,
the <<stylesheet>> is effectively duplicated
and scoped independently to each one.
Authors should avoid using overly-generic selectors
as it can have confusing interactions with the cascade.
<div class="example">
A scoped stylesheet is attached not only to the outermost scoping element,
but to all matching elements.
For example, given the style sheet below
<pre>
@scope div {
span {
color: blue;
}
}
@scope section {
span {
color: orange;
}
}
</pre>
and the following document fragment
<pre>
<div>
<section>
<div>
<span>text</span>
</div>
</section>
</div>
</pre>
the text will be blue.
</div>
''@scope'' rules can be nested.
In this case, just as with the nested style rules,
the selector of an outer ''@scope'' scope-contains
the selector of the inner one.
The specificity of selectors inside the ''@scope'' rule is calculated locally:
the selector specifying the scoping element is ignored.
However, because scoped styles override non-scoped styles,
style rules inside the ''@scope'' will override rules outside of it.
<div class="example">
In the following example, the text would be green:
<pre>
@scope aside {
p { color: green; }
}
aside#sidebar p { color: red; }
</pre>
</div>
Issue: If multiple ''@scope'' rules apply to an element,
should they be cascaded by specificity?
<h3 id='scoping-context'>
Querying the Scoping Context</h3>
<h4 id='scope-pseudo'>
Selecting the Scoping Root: '':scope'' pseudo-class</h4>
In a scoped stylesheet,
the '':scope'' pseudo-class,
defined in [[SELECTORS4]],
matches the <a>scoping root</a>.
<h4 id='scope-content-pseudo'>
Selecting Outside the Scope: '':scope-context()'' pseudo-class</h4>
<div class='issue'>
This would be defined similarly to '':host-context()'',
but matching the ancestors of the <a>scoping root</a> instead.
However, since for scoped stylesheets you may want the ability to match complex selectors against the outside tree,
rather than a single compound selector,
we may want to instead use a more general mechanism that doesn't syntactically invert the order of tree elements.
Possible ideas:
<pre>
:scope-context(<<selector>>) div {...}
scope(<<selector>>) div {...}
\scope <<selector>>\ div {...}
<<selector>> \scope\ div {...}
</pre>
This functionality would replace ''@global'', which is a poor excuse for a selector.
</div>
<h2 id='shadow-dom'>
Shadow Encapsulation</h2>
The Shadow DOM spec augments the DOM with several new concepts,
several of which are relevant to CSS.
A <dfn export>shadow tree</dfn> is a document fragment
that can be attached to any element in the DOM.
The root of the <a>shadow tree</a> is a <dfn export>shadow root</dfn>,
a non-element node which is associated with a <a>shadow host</a>.
An element can have any number of <a>shadow trees</a>,
which are ordered by creation time.
The most recently-created <a>shadow tree</a> on an element
is the <dfn export>youngest shadow tree</dfn> for that element.
An element with a <a>shadow tree</a> is a <dfn export>shadow host</dfn>.
It is the <dfn export>host element</dfn> for its shadow trees.
The descendants of a <a>shadow host</a>
must not generate boxes in the formatting tree.
Instead, the contents of the <a>youngest shadow tree</a> generate boxes
as if they were the contents of the element instead.
In several instances in shadow DOM,
elements don't have element parents
(instead, they may have a <a>shadow root</a> as parent,
or something else).
An element without a parent,
or whose parent is not an element,
is called a <dfn export>top-level element</dfn>.
While the children of a <a>shadow host</a> do not generate boxes normally,
they can be explicitly pulled into a <a>shadow tree</a> and forced to render normally.
This is done by marking the elements as <dfn export>distributed nodes</dfn>
for an <dfn export>insertion point</dfn> element.
This specification does not define how to mark elements as <a>distributed nodes</a>,
instead leaving that to the Shadow DOM spec.
At the time this spec is written, however,
only <a element>content</a> elements in a <a>shadow tree</a> can be <a>insertion points</a>.
An <a>insertion point</a> must not generate any boxes.
Instead, its <a>distributed nodes</a> generate boxes as normal,
as if they all replaced the <a>insertion point</a> in-place.
<span class='note'>(Akin to the behavior of 'display-outside: contents'.)</span>
<h3 id='selectors-data-model'>
Shadow DOM Selection Model</h3>
Elements in the DOM
have zero or more <a>shadow trees</a>
and zero or more <a>distributed nodes</a>.
Note: The "descendants" of an element
are based on the children of the element,
which does not include the <a>shadow trees</a> or <a>distributed nodes</a> of the element.
When a selector is matched against a <a>shadow tree</a>,
the <a>selector match list</a>
is initially the <a>shadow host</a>,
followed by all the <a>top-level elements</a> of the <a>shadow tree</a>
and their descendants,
ordered by a pre-order traversal.
A selector is <dfn>in the context of a shadow tree</dfn>
if it is in a stylesheet attached to the shadow tree
(that is, present in the <code>ShadowRoot.styleSheets</code> list),
or it is used in an API that is <dfn>rooted in a shadow tree</dfn>.
<div class='issue'>
Need to get DOM to hook this term.
<code>querySelector()</code>/etc are <a>rooted in a shadow tree</a>
if they're called on a ShadowRoot or an element in a shadow tree.
</div>
<h4 id='host-element-in-tree'>
Host Elements in a Shadow Tree</h4>
A <a>shadow host</a> is outside of the <a>shadow trees</a> it hosts,
but it is sometimes useful to be able to style it from inside the <a>shadow tree</a> context.
For the purpose of Selectors,
a <a>host element</a> also appears in each of its <a>shadow trees</a>,
with the contents of the <a>shadow tree</a> treated as its children.
If an element has multiple <a>shadow trees</a>,
it appears in each <a>shadow tree's</a> context independently;
each <a>shadow tree</a> sees <em>itself</em> as the contents of the <a>host element</a>,
not the other <a>shadow trees</a>.
When considered within its own <a>shadow trees</a>,
the <a>host element</a> is <a>featureless</a>.
Only the '':host'', '':host()'', and '':host-context()'' pseudo-classes are allowed to match it.
<details class='why'>
<summary>Why is the shadow host so weird?</summary>
The <a>shadow host</a> lives outside the <a>shadow tree</a>,
and its markup is in control of the page author,
not the component author.
It would not be very good if a component used a particular class name
internally in a <a>shadow tree</a>,
and the page author using the component accidentally <em>also</em>
used the the same class name and put it on the <a>host element</a>.
Such a situation would result in accidental styling
that is impossible for the component author to predict,
and confusing for the page author to debug.
However, there are still some reasonable use-cases for letting a stylesheet in a <a>shadow tree</a>
style its <a>host element</a>.
So, to allow this situation but prevent accidental styling,
the <a>host element</a> appears but is completely featureless
and unselectable except through '':host''.
</details>
<h3 id='selectors'>
Shadow DOM Selectors</h3>
Shadow DOM defines a few new selectors
to help select elements in useful way related to Shadow DOM.
Issue: This section is still under discussion.
Feedback and advice on intuitive syntax for the following functionality
would be appreciated.
<h4 id='host-selector'>
Selecting Into the Light: the '':host'', '':host()'', and '':host-context()'' pseudo-classes</h4>
The <dfn selector>:host</dfn> pseudo-class,
when evaluated <a>in the context of a shadow tree</a>,
matches the <a>shadow tree's</a> <a>host element</a>.
In any other context,
it matches nothing.
The <dfn selector id="selectordef-host-function" lt=':host()'>:host()</dfn> function pseudo-class
has the syntax:
<pre>:host( <<compound-selector>> )</pre>
When evaluated <a>in the context of a shadow tree</a>,
it matches the <a>shadow tree's</a> <a>host element</a>
if the <a>host element</a>,
in its normal context,
matches the selector argument.
In any other context,
it matches nothing.
<div class='example'>
For example, say you had a component with a <a>shadow tree</a> like the following:
<pre>
<x-foo class="foo">
<"shadow tree">
<div class="foo">...</div>
</>
</x-foo>
</pre>
For a stylesheet within the <a>shadow tree</a>:
* '':host'' matches the <code><x-foo></code> element.
* ''x-foo'' matches nothing.
* ''.foo'' matches only the <code><div></code> element.
* ''.foo:host'' matches nothing
* '':host(.foo)'' matches the <code><x-foo></code> element.
</div>
Ordinary, selectors within a <a>shadow tree</a>
can't see elements outside the <a>shadow tree</a> at all.
Sometimes, however, it's useful to select an ancestor that lies somewhere outside the shadow tree,
above it in the document.
<div class='example'>
For example, a group of components can define a handful of color themes
they they know how to respond to.
Page authors could opt into a particular theme
by adding a specific class to the components,
or higher up in the document.
</div>
The <dfn selector>:host-context()</dfn> functional pseudo-class tests whether there is an ancestor,
outside the <a>shadow tree</a>,
which matches a particular selector.
Its syntax is:
<pre>:host-context( <<compound-selector>> )</pre>
When evaluated <a>in the context of a shadow tree</a>,
the '':host-context()'' pseudo-class matches the <a>host element</a>,
if the <a>host element</a> or one of its ancestors matches the provided <<compound-selector>>.
For the purpose of this pseudo-class,
the "ancestor" of an element is:
: if the element is a <a>distributed node</a>
:: the <a element>content</a> element it is ultimately distributed to.
: if the element is a top-most element in a shadow tree
:: the <a>host element</a>
: otherwise
:: the element's parent,
if it has one.
Note: This means that the selector pierces through shadow boundaries on the way up,
looking for elements that match its argument,
until it reaches the document root.
<h4 id='shadow-pseudoelement'>
Selecting Into the Dark: the ''::shadow'' pseudo-element</h4>
If an element has at least one <a>shadow tree</a>,
the <dfn>::shadow</dfn> pseudo-element matches the <a>shadow roots</a> themselves.
In HTML, the <a>shadow root</a> is represented by {{ShadowRoot}} objects.
The ''::shadow'' pseudo-element must not generate boxes,
unless specified otherwise in another specification.
However, for the purpose of Selectors,
the ''::shadow'' pseudo-element is considered to be the root of the <a>shadow tree</a>,
with the <a>top-level elements</a> in the <a>shadow tree</a> the direct children of the ''::shadow'' pseudo-element.
<div class='example'>
For example, say you had a component with a <a>shadow tree</a> like the following:
<pre>
<x-foo>
<"shadow tree">
<div>
<span id="not-top">...</span>
</div>
<span id="top">...</span>
</>
</x-foo>
</pre>
For a stylesheet in the outer document,
''x-foo::shadow > span'' matches ''#top'',
but not ''#not-top'',
because it's not a <a>top-level element</a> in the <a>shadow tree</a>.
If one wanted to target ''#not-top'',
one way to do it would be with ''x-foo::shadow > div > span''.
However, this introduces a strong dependency on the internal structure of the component;
in most cases, it's better to use the descendant combinator,
like ''x-foo::shadow span'',
to select all the elements of some type in the <a>shadow tree</a>.
</div>
<div class='example'>
If an element has multiple <a>shadow trees</a>,
a ''::shadow'' pseudo-element selects <em>all</em> of the corresponding <a>shadow roots</a>.
Similarly,
inside of a <a>shadow tree</a>,
a selector like '':host::shadow div'' selects the <a element>div</a> elements in <em>all</em> the <a>shadow trees</a> on the element,
not just the one containing that selector.
</div>
<h4 id='content-combinator'>
Selecting Shadow-Projected Content: the ''::content'' pseudo-element</h4>
The <dfn selector>::content</dfn> pseudo-element matches the list of <a>distributed nodes</a> itself,
on elements that have them.
<p class="issue">
''::content'' is a confusingly general name for something that is specific
to the projected content of a shadow tree.
The ''::content'' pseudo-element must not generate boxes,
unless specified otherwise in another specification.
However, for the purpose of Selectors,
the ''::content'' pseudo-element is considered to be the parent of the <a>distributed nodes</a>.
<div class="example">
For example, say you had a component with both children and a shadow tree,
like the following:
<pre>
<x-foo>
<div id="one" class="foo">...</div>
<div id="two">...</div>
<div id="three" class="foo">
<div id="four">...</div>
</div>
<"shadow tree">
<div id="five">...</div>
<div id="six">...</div>
<content select=".foo"></content>
</"shadow tree">
</x-foo>
</pre>
For a stylesheet within the <a>shadow tree</a>,
a selector like ''::content div''
selects ''#one'', ''#three'', and ''#four'',
as they're the elements distributed by the sole <a element>content</a> element,
but not ''#two''.
If only the <a>top-level elements</a> distributed the <a element>content</a> element are desired,
a <a>child combinator</a> can be used,
like ''::content > div'',
which will exclude ''#four''
as it's not treated as a child of the ''::content'' pseudo-element.
Note: Note that a selector like ''::content div''
is equivalent to ''*::content div'',
where the ''*'' selects many more elements that just the <a element>content</a> element.
However, since only the <a element>content</a> element has <a>distributed nodes</a>,
it's the only element that has a ''::content'' pseudo-element as well.
</div>
<h4 id='deep-combinator'>
Selecting Through Shadows: the ''>>>'' combinator</h4>
When a <dfn selector id="selectordef-shadow-piercing-descendant-combinator">>>></dfn> combinator
(or <dfn export>shadow-piercing descendant combinator</dfn>)
is encountered in a selector,
replace every element in the <a>selector match list</a>
with every element reachable from the original element
by traversing any number of child lists or shadow trees.
<div class='example'>
For example, say you had a component with a <a>shadow tree</a> like the following:
<pre>
<x-foo>
<"shadow tree">
<div>
<span id="not-top">...</span>
</div>
<span id="top">...</span>
<x-bar>
<"shadow tree">
<span id="nested">...</span>
</>
</x-bar>
</>
</x-foo>
</pre>
For a stylesheet in the outer document,
the selector ''x-foo >>> span''
selects all three of <code><span></code> elements:
''#top'', ''#not-top'', <em>and</em> ''#nested''.
</div>
<h3 id='shadow-cascading'>
Shadow Cascading & Inheritance</h3>
<h4 id='cascading'>
Cascading</h4>
To address the desired cascading behavior of rules targetting elements in shadow roots,
this specification extends the <a href="http://dev.w3.org/csswg/css-cascade/#cascading">cascade order</a>
defined in the Cascade specification. [[!CSS3CASCADE]]
An additional cascade criteria must be added,
between Origin and Scope,
called Shadow Tree.
* When comparing two declarations,
if one of them is in a <a>shadow tree</a>
and the other is in a document that contains that <a>shadow tree</a>,
then for normal rules the declaration from the outer document wins,
and for important rules the declaration from the <a>shadow tree</a> wins.
Note: This is the <em>opposite</em> of how scoped styles work.
* When comparing two declarations,
if both are in <a>shadow trees</a> with the same <a>host element</a>,
then for normal rules the declaration from the <a>shadow tree</a> that was created most recently wins,
and for important rules the declaration from the <a>shadow tree</a> that was created less recently wins.
When calculating <a href="http://dev.w3.org/csswg/css-cascade/#cascade-order">Order of Appearance</a>,
the tree of trees,
defined by the Shadow DOM specification,
is used to calculate ordering.
<h4 id='inheritance'>
Inheritance</h4>
The <a>top-level elements</a> of a <a>shadow tree</a>
inherit from their <a>host element</a>.
<a>Distributed nodes</a> inherit from the parent of the <a element>content</a> element they are ultimately distributed to,
rather than from their normal parent.
<h2 id="fragment-scoping">
Fragmented Styling</h2>
Fragmented content can be styled differently
based on which line, column, page, region, etc.
it appears in.
This is done by using an appropriate <dfn export>fragment pseudo-element</dfn>,
which allows targetting individual fragments of an element
rather than the entire element.
<div class="example">
In our example,
the designer wants to make
text flowing into #region1
dark blue and bold.
This design can be expressed as shown below.
<pre>
#region1::region p {
color: #0C3D5F;
font-weight: bold;
}
</pre>
The ''::region'' pseudo-element
is followed by a ''p'' relative selector in this example.
The color and font-weight declarations will apply
to any fragments of paragraphs that are
displayed in ''#region1''.
The following figure shows how
the rendering changes
if we apply this styling specific to ''#region1''.
Note how less text fits into this box
now that the 'font-weight!!property' is
bold instead of normal.
<figure>
<img src="images/region-styling.png" width="450" alt= "Illustrate how changing region styling affects the flow of content.">
<figcaption>Different rendering with a different region styling</figcaption>
</figure>
</div>
Note: This feature is an extension of ''::first-line'' styling.
<h3 id="the-region-pseudo-element">
Region-based Styling: the ''::region'' pseudo-element</h3>
<div class="issue">
Extend this to specify:
* ''<region-element-selector>::region''
* ''<paginated-element-selector>::page(<page-selector>)''
* ''<multicol-element>::column(<AnB>)''
* ''<fragmented-element-selector>::nth-fragment(<AnB>)''
* ''::first-line''
</div>
A ::region pseudo-element represents a relationship between
a selector that matches a <span>CSS Region</span>,
and a relative selector that matches some named flow content.
This allows style declarations to be applied
to fragments of named flow content flowing
into particular regions.
<pre>
<region selector>::region <content selector> {
... CSS styling declarations ...
}
</pre>
When the ::region pseudo-element is appended to a
<a href="http://www.w3.org/TR/css3-selectors/#selector-syntax">selector</a>
that matches one or more CSS Regions,
this creates a 'flow fragment' selector.
The flow fragment selector specifies
which range of elements in the flow
can be matched by the relative selector.
The relative selector can match elements
in the range(s) (see [[!DOM]]) of the named flow
that are displayed fully or partially
in the selected region(s).
Elements that are fully or partially
in the flow fragment range may match the relative selector.
However, the style declarations only apply
to the fragment of the element
that is displayed in the corresponding region(s).
Only a limited list of properties apply to a ::region pseudo-element:
Issue: Either this list should be all functionally inheritable properties,
or all properties.
Why is it a seemingly-arbitrary subset of all properties, including box properties?
1. <a href="http://www.w3.org/TR/CSS2/fonts.html">font properties</a></li>
2. <a href="http://www.w3.org/TR/CSS2/colors.html">color property</a></li>
3. <a href="http://www.w3.org/TR/css3-color/#transparency">opacity property</a></li>
4. <a href="http://www.w3.org/TR/css3-background/#backgrounds">background property</a></li>
5. 'word-spacing'</li>
6. 'letter-spacing'</li>
7. 'text-decoration'</li>
8. 'text-transform'</li>
9. 'line-height'</li>
10. <a href="http://www.w3.org/TR/css3-text/#justification">alignment and justification properties</a></li>
11. <a href="http://www.w3.org/TR/css3-background/#borders">border properties</a></li>
12. <a href="http://www.w3.org/TR/css3-background/#corners">rounded corner properties</a></li>
13. <a href="http://www.w3.org/TR/css3-background/#border-images">border images properties</a></li>
14. <a href="http://www.w3.org/TR/CSS2/box.html#margin-properties">margin properties</a></li>
15. <a href="http://www.w3.org/TR/CSS2/box.html#padding-properties">padding properties</a></li>
16. 'text-shadow'</li>
17. 'box-shadow'</li>
18. 'box-decoration-break'</li>
19. 'width'</li>
<div class="example" id="region-style-example">
In the following example, the <span>named flow</span> “article-flow” flows
into “region-1” and “region-2”.
<pre>
<style>
#div-1 {
<strong>flow-into: article-flow;</strong>
}
#region-1, #region-2 {
<strong>flow-from: article-flow;</strong>
}
/* region styling */
<strong>#region-1::region p </strong> {
margin-right: 5em;
}
</style>
<body>
<div id="div-1">
<p id="p-1">...</p>
<p id="p-2">...</p>
</div>
<div id="region-1"></div>
<div id="region-2"></div>
</body>
</pre>
<div id="region_styling_illustration">
<img id="region_styling_img_2" src="images/region-styling-2.png" alt= "Example showing how a named flow content fits into regions to illustrate region styling.">
<ul class="swatch-list">
<li><span class="swatch" style= "background:#1C75BC"> </span>div div-1
<li><span class="swatch" style= "background:crimson"> </span>paragraph p-1
<li><span class="swatch" style= "background:white"> </span>paragraph p-2
<li><span class="swatch" style= "background:#E6E7E8"> </span>range of flow that fits into region-1
<li><span class="swatch" style= "background:#BCBEC0"> </span>range of flow that fits into region-2
</ul>
</div>
The region styling applies
to flow content that fits in ''region-1''.
The relative selector matches ''p-1'' and ''p-2''
because these paragraphs
flow into ''region-1''.
Only the fragment of ''p-2''
that flows into ''region-1''
is styled with the pseudo-element.
</div>
All of the selectors
in a ::region pseudo-element
contribute to its <a href="http://www.w3.org/TR/css3-selectors/#specificity">specificity</a>.
So the specificity of the ::region pseudo-element
in the example above would combine
the id selector's specificity
with the specificity of the type selector,
resulting in a specificity of 101.
Selectors that match a given element or element fragment (as described above),
participate in the <a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascading-order">CSS Cascading
order</a> as defined in [[!CSS21]].
Note: Region styling does not apply to nested regions. For example, if a region
''A'' receives content from a flow that contains region ''B'', the content that
flows into ''B'' does not receive the region styling specified for region ''A''.
Issue: We'll need some way to query the styles of a fragment in a particular region.
<code>getComputedStyle()</code> isn't enough,
because an element can exist in multiple regions, for example,
with each fragment receiving different styles.