-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.html
6417 lines (5057 loc) · 242 KB
/
Overview.html
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
<html lang=en>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ http://microformats.org/profile/hcard http://microformats.org/wiki/rel-license">
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<title>CSS Template Layout Module</title>
<meta content="width=device-width" name=viewport>
<link href="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS Template Layout Module" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2016-03-01 name=dcterms.date>
<meta content="Bert Bos" name=dcterms.creator>
<meta content="César Acebal" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css-template-3/"
name=dcterms.identifier>
<link href="../default.css" rel=stylesheet type="text/css">
<style type="text/css">
/* Just in case an incorrect max-width occurs in default.css */
body {max-width: none !important}
/* The TR postprocessor already inserted quotes: */
.css::before, .property::before, .descriptor::before {content: none}
.css::after, .property::after, .descriptor::after {content: none}
.prod { font-family: inherit; font-size: inherit }
pre.prod { white-space: pre-wrap; margin: 1em 0 1em 2em }
code { font-size: inherit; }
.example .visible {border: thin dotted silver}
</style>
<link href="http://www.w3.org/StyleSheets/TR/2016/W3C-ED.css"
rel=stylesheet>
<body class=h-entry>
<div class=head><!--begin-logo-->
<p><a href="https://www.w3.org/"><img alt=W3C height=48
src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width=72></a>
<!--end-logo-->
<h1 class=p-name>CSS Template Layout Module</h1>
<h2 class="no-num no-toc">Editor's Draft 1 March 2016</h2>
<dl>
<dt>This version:
<dd><a class=u-url
href="http://dev.w3.org/csswg/css-template-3/">http://dev.w3.org/csswg/css-template-3/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css-template-3/">https://www.w3.org/TR/css-template-3/</a>
<dt>Previous version:
<dd><a
href="https://www.w3.org/TR/2015/NOTE-css-template-3-20150326/">https://www.w3.org/TR/2015/NOTE-css-template-3-20150326/</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss3-layout%5D%20feedback">www-style@w3.org</a>
with subject line “[css-template-3] <var>… message topic
…</var>” (<a href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class="p-author h-card vcard"><span class="p-name fn">Bert Bos</span>
(<span class="p-org org h-org">W3C</span>) <a class="u-email email"
href="mailto:bert@w3.org" rel=author>bert@w3.org</a>
<dd class="p-author h-card vcard"><span class="p-name fn">César
Acebal</span> (<span class="p-org org h-org">University of
Oviedo</span>)
<dt>Editors' draft:
<dd><a
href="https://drafts.csswg.org/css-template/">https://drafts.csswg.org/css-template/</a>
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2016 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<!--=================================================================-->
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<div class=sidefigure>
<p><img alt="Image: four elements move to four slots in a template"
longdesc=diagram.desc src=diagram.png>
<p class=caption>Above: a typical Web page. Below: the underlying grid
template.
</div>
<p>CSS is a simple, declarative language for creating style sheets that
specify the rendering of HTML and other structured documents. This Note
contains experimental ideas for <em>layout templates</em> and alternative
layout models in CSS.
<p>At the moment, it defines a <em>typographic grid</em> for CSS. It has
features to set up a grid-based template, to style the <a
href="#slot"><em>slots</em></a> of the template and to flow content into
them.
<p>A grid template can be seen as a cross between table layout (align
blocks of text automatically in two-dimensions) and absolute positioning
(position elements in arbitrary order), but it also has unique features of
its own.
<p>Grid templates can also be associated with pages in paged media (via
‘<code class=css>@page</code>’), to create <em>page templates.</em>
<p>Slots can form <a href="#chains0"><em>chains,</em></a> to create
non-rectangular regions. A chain of slots is like a series of small pages:
content is broken at possible page breaks and distributed over the slots.
<p><a href="#region-based-styling"><em>Region-based styling</em></a> allows
content to be styled not only based on its position in the document tree,
but also based on the slot it finds itself in. This is achieved by
allowing slot names to appear in selectors.
<!--=================================================================-->
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss-template-3%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css-template-3” in the subject, preferably like this:
“[<!---->css-template-3<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<p>This draft combines ideas from earlier drafts on Template Layout, Grid
Positioning <a href="#ref-CSS3GRID"
rel=biblioentry>[CSS3GRID]<!--{{CSS3GRID}}--></a> and Grid Layout <a
href="#ref-CSS-GRID-1"
rel=biblioentry>[CSS-GRID-1]<!--{{CSS-GRID-1}}--></a>.
<p>Issues on this draft are mentioned in the text itself and/or in the
on-line Tracker under <a
href="http://www.w3.org/Style/CSS/Tracker/products/15">“Details on
Product CSS3 Template Layout.”</a> <!-- Decided at Sep 2014 ftf: -->
<p><em>This document currently serves as a repository for ideas around
using templates for laying out elements, regions or pages; and for various
alternative layout models. It is expected to be updated, but it is not
expected to become a W3C Recommendation in this form. Instead, ideas may
migrate to other modules of CSS.</em>
<!--=================================================================-->
<nav id=toc>
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<ul class=toc>
<li><a href="#summary-and-use-cases"><span class=secno>1.1.
</span>Summary and use cases</a>
<li><a href="#dependencies"><span class=secno>1.2. </span>Dependencies
on other modules</a>
<li><a href="#values"><span class=secno>1.3. </span>Values</a>
<li><a href="#accessibility"><span class=secno>1.4. </span>A note about
accessibility</a>
</ul>
<li><a href="#stack-of-cards-layout"><span class=secno>2. </span>Stack of
cards layout</a>
<li><a href="#declaring-templates"><span class=secno>3. </span>Declaring
templates</a>
<ul class=toc>
<li><a href="#grid-template"><span class=secno>3.1. </span>Declaring a
template: ‘<code class=property>grid-template-areas</code>’</a>
<li><a href="#grid-column-sizes"><span class=secno>3.2.
</span>Specifying the widths of columns: ‘<code
class=property>grid-template-columns</code>’</a>
<li><a href="#grid-template-row-sizes"><span class=secno>3.3.
</span>Specifying the height of rows: ‘<code
class=property>grid-template-rows</code>’</a>
<li><a href="#grid-shorthand"><span class=secno>3.4. </span>The
‘<code class=property>grid</code>’ and ‘<code
class=property>grid-template</code>’ shorthand properties</a>
<li><a href="#default"><span class=secno>3.5. </span>Default slots</a>
<li><a href="#columns"><span class=secno>3.6. </span>Interaction of
‘<code class=property>grid</code>’ and ‘<code
class=property>columns</code>’</a>
<li><a href="#slot-sizes"><span class=secno>3.7. </span>Calculating the
size of the grid</a>
</ul>
<li><a href="#flow"><span class=secno>4. </span>Flowing content into
slots: ‘<code class=property>flow</code>’</a>
<li><a href="#absolute"><span class=secno>5. </span>Comparison with
‘<code class=css>display: grid</code>’ and ‘<code
class=css>display: inline-grid</code>’</a>
<li><a href="#styling-slots"><span class=secno>6. </span>Styling
slots</a>
<ul class=toc>
<li><a href="#slot-pseudo"><span class=secno>6.1. </span>The ‘<code
class=css>::slot()</code>’ pseudo-element</a>
<li><a href="#the-blank-pseudo-element"><span class=secno>6.2.
</span>The ‘<code class=css>::blank()</code>’ pseudo-element</a>
<li><a href="#content"><span class=secno>6.3. </span>Slots and the
‘<code class=property>content</code>’ property</a>
</ul>
<li><a href="#region-based"><span class=secno>7. </span>Styling the
contents of slots</a>
<li><a href="#rendering-of-grid-elements"><span class=secno>8.
</span>Rendering of grid elements</a>
<ul class=toc>
<li><a href="#vertical-alignment"><span class=secno>8.1.
</span>Vertical alignment of the contents of slots</a>
<li><a href="#paged"><span class=secno>8.2. </span>Breaking grid
elements across pages or columns</a>
<li><a href="#stacking-order"><span class=secno>8.3. </span>Stacking
order</a>
<li><a href="#floating-elements-inside-templates"><span
class=secno>8.4. </span>Floating elements inside templates</a>
</ul>
<li><a href="#page-templates"><span class=secno>9. </span>Page-based grid
templates</a>
<li><a href="#chains"><span class=secno>10. </span>Chaining slots: the
‘<code class=property>chains</code>’ property</a>
<li><a href="#history"><span class=secno>11. </span>History and
discussion</a>
<ul class=toc>
<li><a href="#developing-a-model-of-declaring-using-st"><span
class=secno>11.1. </span>Developing a model of declaring, using,
styling and resizing grids</a>
<li><a href="#syntax-features-and-levels"><span class=secno>11.2.
</span>Syntax, features and levels</a>
<ul class=toc>
<li><a href="#named-vs-numbered-slots"><span class=secno>11.2.1.
</span>Named vs numbered slots</a>
<li><a href="#single-letter-names-vs-identifiers"><span
class=secno>11.2.2. </span>Single letter names vs identifiers</a>
<li><a href="#quoted-names"><span class=secno>11.2.3. </span>Quote
marks to delimit rows or slot names</a>
<li><a href="#display"><span class=secno>11.2.4. </span>Extend
‘<code class=property>display</code>’ or add a grid property</a>
<li><a href="#combining-columns-and-grids"><span class=secno>11.2.5.
</span>Combining columns and grids</a>
<li><a href="#shorthand-vs-single-property"><span class=secno>11.2.6.
</span>Shorthand vs single property</a>
<li><a href="#the-number-of-rows-and-columns"><span
class=secno>11.2.7. </span>The number of rows and columns</a>
<li><a href="#need-fr"><span class=secno>11.2.8. </span>‘<code
class=css>*</code>’ vs ‘<code class=css>fr</code>’</a>
<li><a href="#auto-add"><span class=secno>11.2.9.
</span>Automatically add rows and columns</a>
<li><a href="#rectangular-slots-vs-non-rectangular-slo"><span
class=secno>11.2.10. </span>Rectangular slots vs non-rectangular
slots</a>
<li><a href="#page-grid"><span class=secno>11.2.11. </span>Page
grids</a>
<li><a href="#style-the-slots-pseudo-elements"><span
class=secno>11.2.12. </span>Style the slots (pseudo-elements)</a>
<li><a href="#select-after-pseudo"><span class=secno>11.2.13.
</span>Style the contents of slots (region-based styling)</a>
<li><a href="#orient-the-grid-with-writing-mode-vs-ori"><span
class=secno>11.2.14. </span>Orient the grid with writing mode vs
orient the slots</a>
<li><a href="#star-or-at-sign"><span class=secno>11.2.15.
</span>Indicating the default slot (‘<code class=css>*</code>’
vs ‘<code class=css>@</code>’)</a>
<li><a href="#abspos"><span class=secno>11.2.16. </span>Flowing vs
absolutely positioning content in a grid</a>
<li><a href="#use-the-pseudo-class-to-create-additiona"><span
class=secno>11.2.17. </span>Use the pseudo-class to create
additional slots</a>
<li><a href="#names-for-edges"><span class=secno>11.2.18.
</span>Names for edges</a>
<li><a href="#position-from-the-right-and-bottom"><span
class=secno>11.2.19. </span>Position from the right and bottom</a>
<li><a href="#syntax-features-to-shorten-long-grid-spe"><span
class=secno>11.2.20. </span>Syntax features to shorten long grid
specifications</a>
<li><a href="#fit-content-vs-auto-vshellip"><span
class=secno>11.2.21. </span>‘<code class=css>fit-content</code>’
vs ‘<code class=css>auto</code>’ vs…</a>
<li><a href="#vert-align"><span class=secno>11.2.22. </span>Vertical
alignment inside slots</a>
<li><a href="#horizontal-alignment-inside-slots"><span
class=secno>11.2.23. </span>Horizontal alignment inside slots</a>
<li><a href="#auto-margins-on-slots"><span class=secno>11.2.24.
</span>Auto margins on slots</a>
<li><a href="#page-floats"><span class=secno>11.2.25. </span>Page
floats</a>
<li><a href="#break-properties"><span class=secno>11.2.26.
</span>Break-* properties</a>
<li><a href="#next-same"><span class=secno>11.2.27. </span>Automatic
placement of elements</a>
<li><a href="#the-names-of-the-properties"><span class=secno>11.2.28.
</span>The names of the properties</a>
</ul>
</ul>
<li><a href="#conformance"><span class=secno>12. </span>Conformance</a>
<li><a href="#changes"><span class=secno>13. </span>Changes</a>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc--> </nav>
<!--=================================================================-->
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p><em>(This section is not normative.)</em>
<h3 id=summary-and-use-cases><span class=secno>1.1. </span>Summary and use
cases</h3>
<div class=sidefigure>
<p><img alt="Image: four elements move to four slots in a template"
longdesc=diagram.desc src=diagram.png>
<p class=caption>Above: a typical Web page. Below: the underlying grid
template. It has four slots, a, b, c and d and the grid template is
defined by ‘<code class=css>grid: "a a a a a a a" "b c c c c d
d"</code>’.
</div>
<p class=mtb>The styling of a Web page, a form or a graphical user
interface can roughly be divided into two parts: (1) defining the overall
“grid” of the page or window and (2) specifying the fonts, indents,
colors, etc., of the text and other objects. The two are not completely
separate, of course, because indenting or coloring a text influences the
perceived grid as well. Nevertheless, when one separates the parts of a
style that should change when the window gets bigger from the parts that
stay the same, one often finds that the grid changes (different number of
columns and rows, different order for the blocks of content, less or more
open space between those blocks, etc.), while fonts, colors, indents,
numbering styles, and many other things don't have to change, until the
size of the window becomes extreme.
<p>The properties in this specification associate a layout grid with an
element (or with a page, see below). Rather than rendering all descendants
of an element in a single flow, they give an element multiple flows,
called <a href="#slot">slots,</a> placed on an invisible grid by means of
a <span>grid template.</span> The descendants are given a ‘<a
href="#flow0"><code class=property>flow</code></a>’ property to
designate the slot into which they flow.
<p>Because layouts on the Web have to adapt to different window and paper
sizes, the rows and columns of the grid can be made fixed or flexible in
size.
<p class=note>In some typographical traditions, the slots are called
“<span class=index id=fields
title="field (of a typographical grid)">fields</span>” or “<span
class=index id=spatial-zones. title="spatial zone">spatial
zones.</span>” Traditionally, also, all columns have the same width,
called the “<span class=index id=module
title="module (of a typographical grid)">module</span>” or “<span
class=index id=unit title="unit (of a typographical grid)">unit</span>.”
The horizontal lines of a grid that define the rows are sometimes called
“<span class=index id=flow-lines. title="flow line">flow
lines.</span>” Some traditions make the space between pieces of content
an explicit part of the grid, some consider the space part of the content:
Both styles are possible in CSS, the latter by using the ‘<a
href="#margin"><code class=property>margin</code></a>’ property, the
former by using the ‘<code class=css>.</code>’ symbol in a grid
template.
<p>The typical use cases for these properties include:
<ul>
<li>
<p>Complex Web pages, with multiple navigation bars in fixed positions,
areas for advertisements, etc.
<li>
<p>Complex forms, where the alignment of labels and form fields may be
easier with the properties of this module than with the properties for
tables, floats and margins.
<li>
<p>GUIs, where buttons, toolbars, labels, icons, etc., are aligned in
complex ways and have to stay aligned (and not wrap, for example) when
the window is resized.
<li>
<p>Paged displays (e.g., printed media) where each page is divided into
fixed areas for different kinds of content.
<li>
<p>Complex pages with multiple regions, where the style of the text does
not only depend on the type of element it comes from, but also on the
region it is displayed in (<a
href="#region-based-styling"><em>region-based styling</em></a>).
<li>Paged displays with complex running headers and footers, e.g., running
headers that are in between parts of the page content, rather than at the
edge of the page.
</ul>
<p>Once a grid template has been defined, it can also be used to position
elements without adding them to a flow. Setting ‘<code
class=css>display: grid</code>’ on a grid element makes all children
into separate flows and automatically distributes them over the grid. This
is explained in <cite>CSS Grid Layout</cite> <a href="#ref-CSS-GRID-1"
rel=biblioentry>[CSS-GRID-1]<!--{{!CSS-GRID-1}}--></a>.
<p>Template-based positioning makes many traditional uses of absolute
positioning unnecessary. Like absolute positioning, grid templates are
especially useful for aligning elements that don't have simple
relationships in the source (parent-child, ancestor-descendant, immediate
sibling). But in contrast to absolute positioning, the elements are not
positioned with the help of horizontal and vertical coordinates, but by
flowing them into a template that is very much like a table: The size and
alignment of elements are governed implicitly by the rows and columns of
the template, and can automatically adapt to the overall size of the
element and to the content in each row and column.
<div class=example>
<p>In this example, the four children of an element are assigned to four
slots (called a, b, c and d) in a 2×2 template. (All mark-up examples in
this specification are HTML fragments, unless otherwise stated.)
<div class=sidefigure>
<p><img alt="Image: sample rendering" longdesc=aapje.desc src=aapje.png>
<p class=caption>Each element occupies one slot. In this template, all
slots have the same size.
</div>
<pre>
<style type="text/css">
dl { grid: "a b"
"c d" }
#sym1 { flow: a }
#lab1 { flow: b }
#sym2 { flow: c }
#lab2 { flow: d }
</style>
<dl>
<dt id=sym1>A
<dd id=lab1>A is een aapje
<dt id=sym2>B
<dd id=lab2>B is de bakker
</dl>
</pre>
<p><a href=ex-aapje.html>Try it out!</a> (Uses a JavaScript emulation in
browsers that do not implement grid templates natively.)
</div>
<div class=example>
<p>Templates can also help with device-independence. This example uses
Media Queries <a href="#ref-MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> to change the overall
layout of a page from 3-column layout for a wide screen to a 1-column
layout for a narrow screen. It assumes the page has been marked-up with
logical sections with IDs.
<pre>
@media all
{
body { grid: "a a a"
"b c d" }
#head { flow: a }
#nav { flow: b }
#adv { flow: c }
#body { flow: d }
}
@media all and (max-width: 500px)
{
body { grid: "a"
"b"
"c" }
#head { flow: a }
#nav { flow: b }
#adv { display: none }
#body { flow: c }
}
</pre>
</div>
<div class=example>
<p>The slots in a grid do not overlap, unless with negative margins. Here
is how the <a
href="http://www.csszengarden.com/?cssfile=/026/026.css&page=0">
“zunflower” design</a> of the CSS Zen Garden could be done:
<pre>
#container {grid: "A B C"}
#container::slot(A) {box-shadow: 0.5em 0.5em 0.5em; z-index: 1}
#container::slot(B) {box-shadow: 0.5em 0.5em 0.5em; margin-left: -2em}
#intro {flow: A}
#supportingText {flow: B}
#linkList {flow: C}
</pre>
</div>
<div class=example>
<p>Template-based positioning borrows some concepts from table layout, in
particular the idea of aligning elements in rows and columns, so that
they constrain one another's size. But there are also differences. This
example shows some of them. Assume this document fragment:
<pre>
<div class=group>
<div>aa aa aa aa aa aa</div>
<div>bbb</div>
<div class=menu>ccccc</div>
</div>
</pre>
<p>We can lay it out as three columns, as the following illustrations
show. The style sheet would contain the following.
<pre>
.group {display: table}
.group > div {display: table-cell}
</pre>
<div class=figure>
<p><img alt="[Three unequal cells]" longdesc=table1.desc src=table1.png>
<p class=caption>Example of rendering with a table.
</div>
<p>We can also use a template, in which case the style sheet would contain
this:
<pre>
.group {grid: "a b c"}
.group > div {flow: a}
.group > div + div {flow: b}
.group > div + div + div {flow: c}
</pre>
<p>By default, the table is as wide as needed to fit its contents. To make
sure it is as wide as its containing block, we need to add
<pre>.group {display: table; <i>width: 100%</i>}</pre>
<p>That is not needed for the grid template, but, on the other hand, if we
want the template to fit its contents, we would need to say so:
<pre>.group {grid: "a b c"; <i>width: fit-content</i>}</pre>
<p>(See <a href="#ref-CSS3BOX"
rel=biblioentry>[CSS3BOX]<!--{{!CSS3BOX}}--></a> for the definition of
the ‘<a href="#width"><code class=property>width</code></a>’
property.) The columns of the template are by default all the same size.
The columns of the table satisfy certain constraints, but their sizes may
differ. We can make them all the same by adding a rule (see <a
href="#ref-CSS3TBL" rel=biblioentry>[CSS3TBL]<!--{{!CSS3TBL}}--></a>):
<pre>.group {display: table; width: 100%; <i>table-layout: fixed</i>}</pre>
<div class=figure>
<p><img alt="[Three equal cells]" longdesc=table2.desc src=table2.png>
<p class=caption>Example of rendering with equal columns.
</div>
<p>In both styles, we can set a column to a certain size:
<pre>div:nth-child(3) {<i>width: 3em</i>}</pre>
<p>resp.,
<pre>.group {grid: <i>* * 3em</i> "a b c"}</pre>
<div class=figure>
<p><img alt="[Two equal cells, third is 3em wide]" longdesc=table3.desc
src=table3.png>
<p class=caption>Example of rendering with a fixed third column and the
other two columns of equal width.
</div>
<p>If there is an unknown number of columns (children of the div.group
element), the style sheet for the table model will automatically take
them into account. The style sheet for the template model, however,
creates a template of exactly three columns and can't handle tables with
an unknown number of columns. The extra elements will be added into the
default slot (in this case the ‘<code class=css>a</code>’ slot).
<p>(However, setting ‘<a href="#display0"><code
class=property>display</code></a>’ to ‘<a href="#grid"><code
class=property>grid</code></a>’ on the grid element creates a different
kind of grid, that <em>does</em> grow, see <a
href="#absolute">“Comparison with ‘<code class=css>display:
grid</code>’ and ‘<code class=css>display:
inline-grid</code>’”</a> below.)
<p>In both models, elements can have borders, but only in the table model
can borders be collapsed, which makes setting borders easier in the table
model:
<pre>
.group {display: table; <i>border-collapse: collapse</i>}
.group > div {<i>border: solid</i>}
</pre>
<p>resp.,
<pre>
.group > div {<i>border: solid; border-left: none</i>}
.group > div:first-child {<i>border-left: solid</i>}
</pre>
<p>In the template model, the order of the elements is explicit, and thus
it is possible to reverse the order of the columns:
<pre>
.group > div {flow: <i>c</i>}
.group > div + div {flow: b}
.group > div + div + div {flow: <i>a</i>}
</pre>
<div class=figure>
<p><img alt="[Different contents for the cells]" longdesc=table4.desc
src=table4.png>
<p class=caption>Example of rendering with the contents of the three
columns reversed: the third element is shown in the first slot and the
first element in the third slot.
</div>
<p>In the table model, the order of the rows and columns is given by the
document source and thus cannot be changed.
</div>
<div class=example>
<p>[Editorial note: Remove this example if the ‘<a
href="#content1"><code class=property>content</code></a>’ property will
<em>not</em> be allowed on elements, as it is currently expected to be.]
<p>This example shows a way to move notes to the end of a section.
“Notes” in this example refers to elements in HTML with a class of
“note”. A fragment of HTML such as
<pre>
<div class=section>
<p>The balubious coster of the fifth secter<span
class=note> The sixth secter coster is a difter
manon.</span> of The Rollow Carpug mentizes a costernica.
<p>…
</div>
</pre>
<p>with this style sheet
<pre>
div.section {
grid: "*"
"F"}
.note {
flow: F;
content: counter(note) ".\A0" contents;
counter-increment: note;
font-size: smaller}
.note::before {
content: counter(note);
vertical-align: super;
font-size: larger}
</pre>
<p>results in a rendering similar to this:
<div class=figure>
<p><img
alt="Same text, with the SPAN replaced by “(1)” and its content moved to the end."
longdesc=footnotes.desc src=footnotes.png>
<p class=caption>Rendering of a text with footnotes.
</div>
<p>The “Generated content for paged media” module <a
href="#ref-CSS3GCPM" rel=biblioentry>[CSS3GCPM]<!--{{CSS3GCPM}}--></a> is
expected to define specific features for footnotes that are both easier
and more powerful than this example.
</div>
<div class=example>
<p>This example shows the use of <a class=index href="#chain."
id=chained-regions title=chain>chained regions:</a> text from region 1
continues in region 2, 3 and 4. And it shows how to use pseudo-elements
to style text in a particular region: text in region 1 is bigger than in
other regions.
<div class=figure>
<p><img alt="Image of a complex, 3-column layout"
longdesc=regions-intro-rendering.desc src=regions-intro-rendering.png>
<p class=caption>Example rendering
</div>
<p>We assume a document fragment similar to this:
<pre>
<div id=article>
<h1>Introduction</h1>
<p><img src="sunset" alt="">
<p>This is an example…
<h1>More Details</h1>
<p>This illustrates…
<p>Then, the example…
<p>Finally, this…
</div>
</pre>
<p>The style sheet makes the DIV into a grid element with five regions,
called A, *, b, c and d. The regions are grouped into two chains: region
A on its own, and the chain consisting of *, b, c and d.
<pre>
#article {
<a class=index href="#grid" id=grid0>grid</a>: "A A c"
"A A c"
"* * c"
"a b c";
<a
class=index href="#chains0" id=chains1>chains</a>: * a b c }
</pre>
<p>The ‘<code class=css>*</code>’ is a special name. It indicates the
<a href="#default-slot."><em>default slot,</em></a> the slot where
content goes if it doesn't have an explicit ‘<a href="#flow0"><code
class=property>flow</code></a>’ property. We could have used a normal
letter and added an explicit ‘<a href="#flow0"><code
class=property>flow</code></a>’ property to the children of the DIV,
but by using * we don't have to. All children thus go into region * (and
continue in a, b and c as needed). The IMG element goes into region A. We
assume for simplicity that there is only one IMG element:
<pre>#article img { flow: A }</pre>
<p>The text in region * is bolder, larger and a different color than in
the other regions. Also, an H1 that falls into this region is rendered
differently from other H1s:
<pre>
<a class=index href="#atregion" id=atregion0>@region</a> ::slot(*)
{
* {
font-weight: bold;
color: #0C3D5F;
font-size: larger }
h1 {
color: crimson;
display: run-in }
}
</pre>
<p>(For brevity, the example doesn't show the style rules to set the color
and background, to make the text justified, add the left border to the
second H1, etc.)
<p>As the image shows, the text of the last paragraph isn't complete and
presumably continues somewhere else, but that part is outside the scope
of this example. In paged media, we could attach the grid template to a
page instead of an element and let the text continue on the next page; we
could also make slot c into a multi-column element so that the text forms
additional columns to the right of current image (see <a
href="#ref-CSS3GCPM" rel=biblioentry>[CSS3GCPM]<!--{{CSS3GCPM}}--></a>
for some ideas), or there could be a scrollbar on slot c.
</div>
<div class=example>
<p>This example shows three ways to align the contents of a fixed-height
paragraph to the bottom of the box:
<dl>
<dt>Method 1
<dd>
<pre>P {height: 20em; grid: "." "*" fit-content}</pre>
<dt>Method 2
<dd>
<pre>P {height: 20em; grid: "*"}
P::slot(*) {vertical-align: bottom}</pre>
<dt>Method 3
<dd> [Editorial note: Remove method 3 if <a class=index
href="#vertical-align" id=vertical-align0>vertical-align</a> will
<em>not</em> be generalized to apply to all blocks.]
<pre>P {height: 20em; vertical-align: bottom}</pre>
</dl>
<p>However, the styles differ in case the content is taller than 20 em
and overflows: the first style has a baseline-aligned content which will
thus overflow <em>below</em> the element's box; the second example has
bottom-aligned content, which will thus overflow <em>above</em> the
element's box.
</div>
<div class=example>
<p>This example (based on a challenge by Andrew Fedoniouk) shows how a
grid template can be used to display six items in two rows of three.
Assume the following document:
<pre>
<p>
<span>...</span>
<span>...</span>
<span>...</span>
<span>...</span>
<span>...</span>
<span>...</span>
</p>
</pre>
<p>The simplest way to break this into two lines (or more) is to add a
hard line break after the third SPAN: ‘<code
class=css>span:nth-child(3)::after {content: "\A"; white-space:
pre}</code>’. That works fine, unless the SPANs are inline blocks
(‘<code class=css>span {display: inline-block}</code>’). Another way
is to float all SPANs and add a ‘<code class=property>clear</code>’
property on the fourth: ‘<code class=css>span {float: left}
span:nth-child(4) {clear: left}</code>’. But if the SPANs have
different heights or baselines, their vertical alignment will be
different than if they were on the same line.
<p>With a grid template, we can say that the P has not one, but two flows,
a and b, the second one positioned below the first; and then we assign
the fourth and subsequent SPANs to the “b” flow. (The others
automatically go into the default, first flow.)
<pre>
p {grid: "a" "b"}
span:nth-child(n+4) {flow: b}
</pre>
<p>This almost works. There is just a subtle issue with the spaces between
the SPANs. We moved the last three SPANs to flow b, but we have no way to
move the spaces between them. They remain in the default (first) slot.
(They collapse, as there is nothing left between them, so we don't
actually see them anymore.) To get spaces between the SPANs in slot b, we
need to generate new spaces:
<pre>span:nth-child(n+4)::after {content: " "}</pre>
<p class=issue>This space handling is not very intuitive. One might expect
there to be a way to say “select everything from this element onward”
or maybe a pseudo-element selector for the text between elements. Or a
new property to specify different ways to handle the anonymous text
inside a grid element. For the moment, there is no such thing.
Suggestions are welcome.
<p>If, on the other hand, we <em>don't</em> want spaces between the SPANs,
then the question becomes how to get rid of the spaces between the SPANs
in the first row. There are several ways of doing that. One way is to
explicitly flow the three first SPANs to slot “a”:
<pre>span {flow: a}</pre>
<p>The SPANs are thus taken out of the P, causing the P's spaces to end up
next to each other at the start of flow “a” and collapse away.
Another, maybe more intuitive way is to set the spaces to zero width in
the P, and then back to normal in the SPANs (see ‘<a
href="#word-spacing"><code class=property>word-spacing</code></a>’ in
<a href="#ref-CSS-TEXT-3"
rel=biblioentry>[CSS-TEXT-3]<!--{{CSS-TEXT-3}}--></a>):
<pre>
p {word-spacing: -100%}
span {word-spacing: normal}
</pre>
<p>[Editorial note: Remove this last method if percentage values on ‘<a
href="#word-spacing"><code class=property>word-spacing</code></a>’ will
not be allowed. They currently (March 2015) have Working Draft status.]
</div>
<div class=example>
<p>This example uses a <a href="#page-based-template"><em>page-based
template</em></a> to create a running header that is not at the top of
the page, but exactly in the middle. We need to define our own page
template for this, because the predefined page template of <a
href="#ref-CSS3PAGE" rel=biblioentry>[CSS3PAGE]<!--{{CSS3PAGE}}--></a>
only has margin boxes along the edge of the page.
<pre>
@page {
grid:
"top-half"
"running-header" 3em
"bottom-half";
chains: top-half bottom-half
}
::slot(running-header) {
content: "My Magazine - page " counter(page) " - February 2013";
text-align: center;
<a
class=index href="#vertical-align"