forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeferred-to-level-4.txt
396 lines (324 loc) · 15.7 KB
/
deferred-to-level-4.txt
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
<!--
██████ ██████ ███████ ████████ ████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ████ ██ ██
██████ ██ ██ ██ ████████ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██
██████ ██████ ███████ ██ ████ ██ ██ ██████
-->
<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="https://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="https://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="https://drafts.csswg.org/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="https://drafts.csswg.org/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-list>> {
<<rule-list>>
}
</pre>
where the elements matched by the <<selector-list>>
are <a>scoping roots</a> for the style rules in <<rule-list>>,
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-list>>,
the <<rule-list>> 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-list>>) div {...}
scope(<<selector-list>>) div {...}
\scope <<selector-list>>\ div {...}
<<selector-list>> \scope\ div {...}
</pre>
This functionality would replace ''@global'', which is a poor excuse for a selector.
</div>
<!--
████████ ████████ ███ ██████ ██ ██ ████████ ██ ██ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ███ ███ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██
██████ ████████ ██ ██ ██ ████ ██ ███ ██ ██████ ██ ██ ██ ██ ██████
██ ██ ██ █████████ ██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██ ██ ██ ██ ██ ██████ ██ ██ ████████ ██ ██ ██ ██████
-->
<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 targeting 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="https://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="https://www.w3.org/TR/CSS2/fonts.html">font properties</a></li>
2. <a href="https://www.w3.org/TR/CSS2/colors.html">color property</a></li>
3. <a href="https://www.w3.org/TR/css3-color/#transparency">opacity property</a></li>
4. <a href="https://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="https://www.w3.org/TR/css3-text/#justification">alignment and justification properties</a></li>
11. <a href="https://www.w3.org/TR/css3-background/#borders">border properties</a></li>
12. <a href="https://www.w3.org/TR/css3-background/#corners">rounded corner properties</a></li>
13. <a href="https://www.w3.org/TR/css3-background/#border-images">border images properties</a></li>
14. <a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">margin properties</a></li>
15. <a href="https://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="https://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="https://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.