-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathregions-use-cases.txt
More file actions
424 lines (358 loc) · 12.6 KB
/
regions-use-cases.txt
File metadata and controls
424 lines (358 loc) · 12.6 KB
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
=== Introduction ===
This page captures use cases for CSS Regions (and exclusions).
CSS Regions can be coupled with [[ideas:css3-exclusions-use-cases|CSS Exclusions and Shapes use cases]] for rich layouts with non-rectangular and intruding boxes.
==== Flowing content between arbitrary areas ====
The following image illustrates flowing the same content across regions of different widths. As the content is resized, so are the various regions and the content simply flows between the different regions.
{{:spec:css3-regions:simple_single_thread.png?600|}}
<code css>
/* extract the content of #source into a named flow - 'article' */
#source {
flow-into: article;
}
/* page template arranges columns using a flexbox */
.page {
display:flexbox;
padding:0.5em
}
/* render the content from the 'article' named flow into .region */
.region {
flow-from: article;
background: lightblue;
margin:0.5em;
}
#region_1, #region_3 { width:flex(1); }
#region_2 { width:flex(1.7); height:40%; }
</code>
<code html>
<div id="source">
<p>Lorem ipsum dolor sit amet ...</p>
</div>
<div class="page">
<div id="region_1" class="region"></div>
<div id="region_2" class="region"></div>
<div id="region_3" class="region"></div>
</div>
</code>
==== Flowing content between areas of a non-grid layout ====
{{:spec:css3-regions:regions_non-grid-layout.jpg?600|}}
<code css>
/* extract the content of #source into a named flow - 'article' */
#source {
flow-into: article;
}
/* render the content from the 'article' named flow into .region */
.region {
flow-from: article;
}
#region_1,
#region_2,
#region_3 {
position: absolute;
}
#region_1 {
width: 22%;
height: 100px;
top: 0;
left: 0;
}
#region_2 {
width: 15%;
height: 250px;
bottom: 0;
left: 30%;
}
#region3 {
width: 200px;
height: 320px;
top: 40px;
right: 0;
}
</code>
<code html>
<div id="source">
<p>Lorem ipsum dolor sit amet ...</p>
</div>
<div id="region_1" class="region"></div>
<div id="region_2" class="region"></div>
<div id="region_3" class="region"></div>
</code>
==== Flowing content between areas and overlapping pull quote exclusion ====
Use case from Korean News Paper layout: http://lists.w3.org/Archives/Public/www-archive/2011Oct/att-0033/KoreanNewspapers-exclusionAreas.pdf.
{{:spec:css3-regions:exclusions_pullquote_offset.jpg?600|}}
Sample with CSS Regions and Exclusions
<code css>
/* extract the content of #source into a named flow - 'article' */
#source {
flow-into: article;
}
/* render the content from the 'article' named flow into .region */
.region {
flow-from: article;
}
#region_1,
#region_2 {
float: left;
height: 100%;
}
#region1 {
width: 60%
}
#region_2 {
width: 30%
margin-left: 10%;
}
blockquote {
position:absolute;
height: 200px;
width: 50%;
left: 25%;
top: 35%;
/* exclude surrounding content */
wrap-flow: both;
/* prevent the content from touching the edges of the box */
shape-padding: 20px;
color: lightblue;
font-size: 2em;
}
</code>
<code html>
<div id="source">
<p>Lorem ipsum dolor sit amet ...</p>
</div>
<div id="region_1" class="region"></div>
<div id="region_2" class="region"></div>
<blockquote>Lorem ipsum dolor ...</blockquote>
</code>
==== Flowing content into transformed areas ====
See Stagger and Swagger at http://24ways.org/2009/type-inspired-interfaces
{{:spec:css3-regions:regions_rotated_columns.jpg?600|}}
<code css>
/* extract the content of #source into a named flow - 'article' */
#source {
flow-into: article;
}
/* render the content from the 'article' named flow into .region */
.region {
flow-from: article;
}
#region_1,
#region_2 {
float: left;
width: 45%;
height: 70%;
}
#region_1 {
transform: rotate(6.5deg);
}
#region_2 {
transform: rotate(-5.5deg) translate(0, 40px);
}
</code>
<code html>
<div id="source">
<p>Lorem ipsum dolor sit amet ...</p>
</div>
<div id="region_1" class="region"></div>
<div id="region_2" class="region"></div>
</code>
==== Filtering content - "Breaking news" ====
With CSS Regions I can filter the content and surface it. Possible use cases: "breaking news" lists, terms of content summary, collecting references from a page, such as bugs or external links.
{{:spec:css3-regions:screeny-shot-feb-5-2012-8.14.34-pm.png?600|}}
**Example with extra container**
<code css>
/* extract the breaking news into a separate named flow - 'breaking-news' */
.breaking{
background: yellow;
flow-into: breaking-news;
}
.stories,
.breaking-news{
width:20ex;
height:5ex;
}
/* show only breaking news */
.breaking-news{
flow-from: breaking-news;
}
</code>
<code html>
<h2>Surfacing breaking news</h2>
<ul class="breaking-news"></ul>
<ul class="stories">
<li><a href="//example.com/story/1">A story</a></li>
<li><a href="//example.com/story/2">Another story</a></li>
<li class="breaking"><a href="//example.com/story/3">Something notable</a></li>
<li><a href="//example.com/story/4">Slow news day</a></li>
<li class="breaking"><a href="//example.com/story/5">Critical story</a></li>
</ul>
</code>
**Example with pseudo-element overload**
<code css>
/* extract the breaking news into a separate named flow - 'breaking-news' */
.breaking{
background: yellow;
flow-into: breaking-news;
}
.stories,
.stories::before{
width:20ex;
height:5ex;
}
/* show the breaking news before the other news */
.stories::before{
flow-from: breaking-news;
/* allow scrolling when content overflows the last region in the named flow */
region-fragment: auto;
overflow: auto;
}
</code>
<code html>
<h2>Surfacing breaking news</h2>
<ul class="stories">
<li><a href="//example.com/story/1">A story</a></li>
<li><a href="//example.com/story/2">Another story</a></li>
<li class="breaking"><a href="//example.com/story/3">Something notable</a></li>
<li><a href="//example.com/story/4">Slow news day</a></li>
<li class="breaking"><a href="//example.com/story/5">Critical story</a></li>
</ul>
</code>
Idea from [[https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#shadow-dom-example|Shadow DOM Example]]
==== Converting hard breaks to named flows ====
Some pages (see [[http://ilovetypography.com/2012/04/06/type-camp-india/|Type Camp India]]) break up a single article into segments in order to create the layout they want. Instead of using these hard breaks, the content could go into a named flow and the sections could be turned into regions. The regions can then be sized and arranged according to the layout desired and the content flowed smoothly between them.
If you have markup like this:
<code html>
<div class="segment"><p>Some segment of the content...</p></div>
<img/>
<div class="segment"><p>...next segment of the content...</p></div>
<img/>
<div class="segment"><p>...next segment of the content...</p></div>
...
</code>
You can take the contents of each segment and place them into a named flow:
<code css>
.segment > * {
flow-into: combined-segments;
}
</code>
Then create a region chain out of the segments, usually giving them a height to take up in the layout:
<code css>
.segment {
flow-from: combined-segments;
height: 50vh;
}
</code>
This works only if the class="segment" elements have no direct content, because we only have > * to work with. It would be better if there was an "all content" selector we could use.
==== Capturing region overflow content ====
{{:spec:css3-regions:regions_region-overflow.jpg?600|}}
<code css>
/* extract the content of #source into a named flow - 'article' */
#source {
flow-into: article;
}
.region{
flow-from: article;
}
#region1{
width:25%;
height:30%;
float:left;
}
#region2{
width:65%;
height:30%;
float:right;
}
#region3{
width:100%;
height:60%;
margin-top:10%;
/* Control the overflow behavior of the last region in the named flow */
region-fragment:auto;
overflow:auto;
}
</code>
<code html>
<div id="source">
<p>Lorem ipsum dolor sit amet ...</p>
</div>
<div id="region1" class="region"></div>
<div id="region2" class="region"></div>
<div id="region3" class="region"></div>
</code>
==== Fancy illustration layout ====
{{:spec:css3-regions:advanced_piechart.jpg?600|}}
<code css>
/* extract the content of #source into a named flow - 'article' */
#source{
flow-into: article;
}
/* render the content from the 'article' named flow into .region */
.region {
flow-from: article;
}
#piechart {
position: absolute;
width: 500px;
height: 500px;
right: 0;
}
#slice_1,
#slice_2,
#slice_3,
#slice_4 {
position: absolute;
/* prevent text from touching the edges of the slices */
shape-padding: 10px;
}
#slice_1 {
/* set the shape of the slice */
shape-inside: polygon(x1, y1, x2, y2, x3, y3, ... xn, yn);
/* using SVG for background. shape-inside doesn't affect the box background so background-color won't work */
background-image: url(green_slice.svg);
top: -10px;
left: -10px;
}
#slice_2 {
shape-inside: polygon(x1, y1, x2, y2, x3, y3, ... xn, yn);
background-image: url(tan_slice.svg);
top: 200px;
left: -20px;
}
#slice_3 {
shape-inside: polygon(x1, y1, x2, y2, x3, y3, ... xn, yn);
background-image: url(orange_slice.svg);
top: 350px;
bottom: -10px;
}
#slice_4 {
shape-inside: polygon(x1, y1, x2, y2, x3, y3, ... xn, yn);
background-image: url(yellow_slice.svg);
top: 0;
right: 0;
}
</code>
<code html>
<h1>The <em>not so hidden</em> Cost$</h1>
<div id="source">
<p>Not every meal is going to be ...</p>
</div>
<div id="piechart">
<div id="slice_1" class="region"></div>
<div id="slice_2" class="region"></div>
<div id="slice_3" class="region"></div>
<div id="slice_4" class="region"></div>
</div>
</code>
==== Multi-lingual in parallel columns ====
Pages showing multicolumn layout with two flows, one French and the other English text.
See this real-life example of an airline magazine with english/french side by side.
{{:spec:css3-regions:multi-lingual.png?700|}}
==== Content re-ordering on the client ====
There are content management systems that assemble markup on demand, but have limited options for changing the markup (and therefore the layout) based on the capabilities of the client that requests a page. One not-so-good solution is to offer a separate 'mobile' page using a different URL if there are layout considerations that require re-ordering the markup to achieve the layout desired on mobile. Using named flows and region chains allows you to define radically different layouts based on media queries in your CSS without changing the underlying markup.
==== CSSOM use cases ====
The spec includes more than the usual amount of CSSOM, as the basic capabilities of named flows and region chains are very well suited to being extended via script. Here are some use cases for the scripting access included in the spec.
- Modifying the region chain based on content changes or window resizing. This could involve adding or removing CSS Regions, or changing region geometry. This case makes use of the regionLayoutUpdate event for noticing when changes may be required Then the NamedFlow.overset, NamedFlow.firstEmptyRegionIndex, and Region.regionOverset properties are used to determine what needs done.
- Modifying the content based on the region chain. This is the reverse of the first use case. If the size and position of the region chain is fixed, script can modify the contents (usually through font-size) to make it fit. This can take the form of enlarging headlines to fill the available space, or slightly reducing body text size to bring in a few lines of overset text. NamedFlow.overset is particularly useful here.
- Handing events on named flow contents - using the OM to determine the CSS Region(s) that contain the content. NamedFlow.getRegionsByContent() allows you to move from the contents to the containers.
- Layout extensions implemented via script (script-based layout constraints). If you have a script-based layout system that uses a different set of constraints than existing CSS layout modes, script access to the region chain through NamedFlow.getRegions() and NamedFlow.getRegionsByContent() is required to solve the layout puzzle.
- Paginated views. Until pagination has an agreed-upon solution, script-based paginated views will need OM access to named flow contents and region chains. And the eventual agreed-upon pagination solution will likely have some voids that can be filled by script, so OM access will continue to be useful (for a smaller set of requirements).