-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·4123 lines (3195 loc) · 156 KB
/
Overview.html
File metadata and controls
executable file
·4123 lines (3195 loc) · 156 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
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"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Grid Layout</title>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<style type="text/css">
.example {
clear:both
}
th {
text-align:left
}
.pseudo-code {
font-family:monospace
}
.pseudo-code > ol {
list-style-type:decimal
}
.pseudo-code > ol > li > ol {
list-style-type:lower-latin
}
.pseudo-code > ol > li > ol > li > ol {
list-style-type:lower-roman
}
.pseudo-code ul {
list-style-type:disc
}
dd > p:nth-child(1) {
margin-top:0
}
</style>
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1 class=title id=title>CSS Grid Layout</h1>
<h2 class="no-num no-toc" id=longstatus-date-3-march-2012>Editor's Draft,
13 August 2012</h2>
<dl>
<dt>This version:</dt>
<!-- <dd><a href="http://www.w3.org/TR/2012/ED-css3-grid-layout-20120813/">http://www.w3.org/TR/2012/WD-css3-grid-layout-20120813/</a> -->
<dd><a
href="http://dev.w3.org/csswg/css3-grid-layout/">http://dev.w3.org/csswg/css3-grid-layout/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-grid-layout/">http://www.w3.org/TR/css3-grid-layout/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-grid-layout/">http://dev.w3.org/csswg/css3-grid-layout/</a>
<dt>Previous version
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-grid-layout-20110407/">http://www.w3.org/TR/2011/WD-css3-grid-layout-20110407/</a>
<dt>Issues List:
<dd><a
href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=Grid+Layout&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">In
Bugzilla</a>
<dt>Discussion:
<dd><a
href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a>
with subject line “<kbd>[css3-grid-layout] <var>… message topic
…</var></kbd>”
<dt>Editors:
<dd><a href="mailto:alexmog@microsoft.com">Alex Mogilevsky</a>, Microsoft
Corporation
<dd><a href="mailto:pcupp@microsoft.com">Phil Cupp</a>, Microsoft
Corporation
<dd><a href="mailto:mmielke@microsoft.com">Markus Mielke</a>, Microsoft
Corporation
<dd><a href="mailto:daniel.glazman@disruptive-innovations.com">Daniel
Glazman</a>, Disruptive Innovations
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2012 <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>), All Rights Reserved. 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=abstract0>Abstract</h2>
<div id=abstract>
<p> Grid Layout contains features targeted at web application authors. The
Grid can be used to achieve many different layouts. It excels at dividing
up space for major regions of an application, or defining the
relationship in terms of size, position, and layer between parts of a
control built from HTML primitives.</p>
<p> Like tables, the Grid enables an author to align elements into columns
and rows, but unlike tables, the Grid doesn't have content structure, and
thus enables a wide variety of layouts not possible with tables. For
example, the children of the Grid can position themselves with <a
href="#grid-line"><i>Grid lines</i></a> such that they overlap and layer
similar to positioned elements.</p>
<p> In addition, the absence of content structure in the Grid helps to
manage changes to layout by using fluid and source order independent
layout techniques. By combining media queries with the CSS properties
that control layout of the Grid and its children, authors can adapt their
layout to changes in device form factors, orientation, and available
space, without needing to alter the semantic nature of their content.</p>
</div>
<h2 class="no-num no-toc" id=status-of-this-document>Status of This
Document</h2>
<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> If you wish to make comments regarding this document, please send them
to <a href="mailto:www-style@w3.org">www-style@w3.org</a> (<a
href="mailto:www-style-request@w3.org?subject=subscribe">subscribe</a>, <a
href="http://lists.w3.org/Archives/Public/www-style/">archives</a>). All
feedback is welcome.
<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>.
<h2 class="no-num no-toc" id=table>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#dependencies-on-other-modules"><span class=secno>1.
</span>Dependencies on other modules</a>
<li><a href="#introduction0"><span class=secno>2. </span>Introduction</a>
<ul class=toc>
<li><a href="#basic-capabilities-of-the-grid"><span class=secno>2.1.
</span>Basic Capabilities of the Grid</a>
<li><a href="#adapting-layouts-to-available-space"><span
class=secno>2.2. </span>Adapting Layouts to Available Space</a>
<li><a href="#source-independence0"><span class=secno>2.3. </span>Source
Independence</a>
<li><a href="#grid-layering-of-elements0"><span class=secno>2.4.
</span>Grid Layering of Elements</a>
</ul>
<li><a href="#core-concepts-of-the-grid"><span class=secno>3. </span>Core
Concepts of the Grid</a>
<ul class=toc>
<li><a href="#grid-tracks"><span class=secno>3.1. </span>Grid Tracks</a>
<li><a href="#grid-lines"><span class=secno>3.2. </span>Grid Lines</a>
<li><a href="#grid-areas"><span class=secno>3.3. </span>Grid Areas</a>
</ul>
<li><a href="#defining-the-grid0"><span class=secno>4. </span>Defining the
Grid</a>
<ul class=toc>
<li><a href="#grid-declaration0"><span class=secno>4.1. </span>Grid
Declaration</a>
<li><a href="#grid-rows-and-columns0"><span class=secno>4.2. </span>Grid
Rows and Columns</a>
<li><a href="#named-grid-lines"><span class=secno>4.3. </span>Named Grid
Lines</a>
<li><a href="#repeating-columns-and-rows"><span class=secno>4.4.
</span>Repeating Columns and Rows</a>
<li><a href="#grid-definition-columns-and-grid-definit"><span
class=secno>4.5. </span>Grid-definition-columns and
Grid-definition-rows Properties</a>
<ul class=toc>
<li><a href="#fraction-values-fr0"><span class=secno>4.5.1.
</span>Fraction Values: ‘<code class=property>fr</code>’</a>
<li><a href="#used-values-for-grid-definition-rows-and"><span
class=secno>4.5.2. </span>Used Values for grid-definition-rows and
grid-definition-columns</a>
</ul>
<li><a href="#defining-grid-areas-with-a-template0"><span
class=secno>4.6. </span>Defining Grid Areas with a Template</a>
</ul>
<li><a href="#grid-items0"><span class=secno>5. </span>Grid items</a>
<li><a href="#placing-grid-items"><span class=secno>6. </span>Placing Grid
Items</a>
<ul class=toc>
<li><a href="#grid-row-span-and-grid-column-span0"><span
class=secno>6.1. </span>Grid-row-span and Grid-column-span</a>
<li><a href="#grid-shorthand-properties0"><span class=secno>6.2.
</span>Grid shorthand properties</a>
<li><a href="#anonymous-grid-areas0"><span class=secno>6.3.
</span>Anonymous Grid Areas</a>
<li><a href="#implicit-columns-and-rows"><span class=secno>6.4.
</span>Implicit Columns and Rows</a>
<ul class=toc>
<li><a href="#defining-a-default-size-for-implicit-col"><span
class=secno>6.4.1. </span>Defining a Default Size for Implicit
Columns and Rows</a>
</ul>
<li><a href="#automatic-placement-of-grid-items0"><span class=secno>6.5.
</span>Automatic Placement of Grid Items</a>
<ul class=toc>
<li><a href="#automatic-grid-item-placement-algorithm0"><span
class=secno>6.5.1. </span>Automatic Grid Item Placement Algorithm</a>
</ul>
</ul>
<li><a href="#grid-item-alignment0"><span class=secno>7. </span>Grid Item
Alignment</a>
<ul class=toc>
<li><a href="#impact-of-alignment-on-grid-item-size0"><span
class=secno>7.1. </span>Impact of Alignment on Grid Item Size</a>
</ul>
<li><a href="#drawing-order-of-grid-items0"><span class=secno>8.
</span>Drawing Order of Grid Items</a>
<li><a href="#calculating-the-size-of-grid-tracks"><span class=secno>9.
</span>Calculating the Size of Grid Tracks</a>
<ul class=toc>
<li><a href="#definition-of-terms-for-use-in-calculati"><span
class=secno>9.1. </span>Definition of Terms for use in Calculating Grid
Track Sizes</a>
<li><a href="#grid-track-sizing-algorithm0"><span class=secno>9.2.
</span>Grid Track Sizing Algorithm</a>
</ul>
<li><a href="#defining-the-shrink-to-fit-behavior-of-g"><span
class=secno>10. </span>Defining the Shrink-to-fit Behavior of Grid
Elements</a>
<li class=no-num><a href="#changes-from-previous-version">Changes from
Previous Working Draft</a>
<ul class=toc>
<li class=no-num><a
href="#changes-from-previous-version-12-april-2012">Changes made in 12
April 2012 Editor's Draft</a>
<li class=no-num><a
href="#changes-from-previous-version-2-august-2012">Changes made in 2
August 2012 Editor's Draft</a>
<li class=no-num><a
href="#changes-from-previous-version-13-august-2012">Changes made in 13
August 2012 Editor's Draft</a>
</ul>
<li class=no-num><a href="#acknowledgements">Acknowledgements</a>
<li class=no-num><a href="#references"> References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references"> Normative
references</a>
<li class=no-num><a href="#other-references"> Other references</a>
</ul>
<li class=no-num><a href="#index"> Index</a>
<li class=no-num><a href="#property-index"> Property index</a>
</ul>
<!--end-toc-->
<div class=section id=dependencies>
<h2 id=dependencies-on-other-modules><span class=secno>1.
</span>Dependencies on other modules</h2>
<p> This CSS3 module has normative references to the following other CSS3
modules:</p>
<ul>
<li><a href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>
<li><a href="#CSS3-ALIGN"
rel=biblioentry>[CSS3-ALIGN]<!--{{!CSS3-ALIGN}}--></a>
<li><a href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>
</ul>
<p> This CSS3 module has non-normative (informative) references to the
following other CSS3 modules:</p>
<ul>
<li><a href="#CSS3LAYOUT"
rel=biblioentry>[CSS3LAYOUT]<!--{{CSS3LAYOUT}}--></a>
</ul>
</div>
<!--End section: Dependencies -->
<div class=section id=Introduction>
<h2 id=introduction0><span class=secno>2. </span>Introduction</h2>
<div class=section id=basic-capabilities>
<h3 id=basic-capabilities-of-the-grid><span class=secno>2.1. </span>Basic
Capabilities of the Grid</h3>
<div class=sidefigure> <img
alt="Image: Application layout example requiring horizontal and vertical alignment."
class=figure src="images/basic-form.png">
<p class=caption>Application layout example requiring horizontal and
vertical alignment.</p>
</div>
<p> As websites evolved from simple documents into complex, interactive
applications, tools for document layout, e.g. floats, were not
necessarily well suited for application layout. By using a combination
of tables, JavaScript, or careful measurements on floated elements,
authors discovered workarounds to achieve desired layouts. Layouts that
adapted to the available space were often brittle and resulted in
counter-intuitive behavior as space became constrained. As an
alternative, authors of many web applications opted for a fixed layout
that cannot take advantage of changes in the available rendering space
on a screen.</p>
<p> The layout capabilities of the Grid address these problems. The Grid
provides a mechanism for authors to divide available space for layout
into columns and rows using a set of predictable sizing behaviors.
Authors can then precisely position and size the building block elements
of their application by referencing the <a href="#grid-line"><i>Grid
lines</i></a> between the columns and rows, or by defining and
referencing a <a href="#grid-area-concept"><i>Grid area</i></a>, which
is a rectangular space covering an intersection of columns and rows.
Figure 1 illustrates a basic layout which can be achieved with the Grid.
</p>
<!--End Section: Basic Capabilities of the Grid--></div>
<div class=section id=adapting-to-available-space>
<h3 id=adapting-layouts-to-available-space><span class=secno>2.2.
</span>Adapting Layouts to Available Space</h3>
<div class=sidefigure>
<p> <img
alt="Image: Five grid items arranged according to content size and available space."
src="images/game-smaller.png"></p>
<p class=caption>Five grid items arranged according to content size and
available space.</p>
</div>
<div class=sidefigure>
<p> <img
alt="Image: Growth in the grid due to an increase in available space."
src="images/game-larger.png"></p>
<p class=caption>Growth in the grid due to an increase in available
space.</p>
</div>
<p> The <a href="#grid-element"><i>Grid element</i></a> can be used to
intelligently reflow elements within a webpage. Figure 2 represents a
game with five major areas in the layout: the game title, stats area,
game board, score area, and control area. The author's intent is to
divide the space for the game such that:
<ul>
<li>The stats area always appears immediately under the game title.
<li>The game board appears to the right of the stats and title.
<li>The top of the game title and the game board should always align.
<li>The bottom of the game board and the stats area align when the game
has reached its minimum height, but otherwise the game board will
stretch to take advantage of all the screen real-estate available to
it.
<li>The score area should align into the column created by the game and
stats area, while the controls are centered under the board.
</ul>
<p> As an alternative to using script to control the absolute position,
width, and height of all elements, the author can use the <a
href="#grid-element"><i>Grid element</i></a>, as shown in Figure 3. The
following example shows how an author might achieve all the sizing,
placement, and alignment rules declaratively.</p>
<p> Note that there are multiple ways to specify the structure of the <a
href="#grid-element"><i>Grid element</i></a> and to position and size <a
href="#grid-item"><i>Grid items</i></a>, each optimized for different
scenarios. This example illustrates one that an author may use to define
the position and space for each <a href="#grid-item"><i>Grid
item</i></a> using the ‘<a href="#grid-definition-rows"><code
class=property>grid-definition-rows</code></a>’ and ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ properties of the
<a href="#grid-element"><i>Grid element</i></a>, and the ‘<a
href="#grid-row-position"><code
class=property>grid-row-position</code></a>’, ‘<a
href="#grid-column-position"><code
class=property>grid-column-position</code></a>’, ‘<a
href="#grid-row-span"><code class=property>grid-row-span</code></a>’
and ‘<a href="#grid-column-span"><code
class=property>grid-column-span</code></a>’ properties on each <a
href="#grid-item"><i>Grid item</i></a>.</p>
<pre class=example><style type="text/css">
<style type="text/css">
#grid {
display: grid;
/* Two columns: the first sized to content, the second receives the remaining space, */
/* but is never smaller than the minimum size of the board or the game controls, which */
/* occupy this column. */
grid-column-definition: auto minmax(min-content, 1fr);
/* Three rows: the first and last sized to content, the middle row receives the */
/* remaining space, but is never smaller than the minimum height of the board or stats */
/* areas. */
grid-row-definition: auto minmax(min-content, 1fr) auto
}
/* Each part of the game is positioned between grid lines by referencing the starting grid */
/* line and then specifying, if more than one, the number of rows or columns spanned to */
/* determine the ending grid line, which establishes bounds for the part. */
#title { grid-column-position: 1; grid-row-position: 1 }
#score { grid-column-position: 1; grid-row-position: 3 }
#stats { grid-column-position: 1; grid-row-position: 2; justify-self: start }
#board { grid-column-position: 2; grid-row-position: 1; grid-row-span: 2 }
#controls { grid-column-position: 2; grid-row-position: 3; align-self: center }
</style>
<div id="grid">
<div id="title">Game Title</div>
<div id="score">Score</div>
<div id="stats">Stats</div>
<div id="board">Board</div>
<div id="controls">Controls</div>
</div></pre>
<!--End Section: Adapting to Available Space for Layout--></div>
<div class=section id=source-independence>
<h3 id=source-independence0><span class=secno>2.3. </span>Source
Independence</h3>
<div class=sidefigure>
<p> <img alt="Image: An arrangement suitable for portrait orientation."
src="images/game-portrait.png"></p>
<p class=caption>An arrangement suitable for ‘<code
class=css>portrait</code>’ orientation.</p>
</div>
<div class=sidefigure>
<p> <img alt="Image: An arrangment suitable for landscape orientation."
src="images/game-landscape.png"></p>
<p class=caption>An arrangment suitable for ‘<code
class=css>landscape</code>’ orientation.</p>
</div>
<p> Continuing the prior example, the author also wants the game to adapt
to the space available on traditional computer monitors, handheld
devices, or tablet computers. Also, the game should optimize the
placement of the components when viewed either in landscape or portrait
orientation (Figures 4 and 5). By combining the CSS markup for the <a
href="#grid-element"><i>Grid element</i></a> with media queries, the
author is able to use the same semantic markup, but rearranged
independent of its source order, to achieve the desired layout in both
orientations.</p>
<p> The following example leverages the <a href="#grid-element"><i>Grid
element</i></a>’s ability to name the space which will be occupied by
a <a href="#grid-item"><i>Grid item</i></a>. This allows the author to
avoid rewriting rules for <a href="#grid-item"><i>Grid items</i></a> as
the <a href="#grid-element"><i>Grid element</i></a>’s definition
changes.</p>
<pre class=example><style type="text/css">
@media (orientation: portrait) {
#grid {
display: grid;
/* The rows, columns and areas of the grid are defined visually using the */
/* grid-template property. Each string is a row, and each word an area. */
/* The number of words in a string determines the number of */
/* columns. Note the number of words in each string must be identical. */
grid-template: "title stats"
"score stats"
"board board"
"ctrls ctrls";
/* Columns and rows created with the template property can be assigned a sizing */
/* function with the grid-definition-columns and grid-definition-rows properties. */
grid-definition-columns: auto minmax(min-content, 1fr);
grid-definition-rows: auto auto minmax(min-content, 1fr) auto
}
}
@media (orientation: landscape) {
#grid {
display: grid;
/* Again the template property defines areas of the same name, but this time */
/* positioned differently to better suit a landscape orientation. */
grid-template: "title board"
"stats board"
"score ctrls";
grid-definition-columns: auto minmax(min-content, 1fr);
grid-definition-rows: auto minmax(min-content, 1fr) auto
}
}
/* The grid-area property places a grid item into named region (area) of the grid. */
#title { grid-area: title }
#score { grid-area: score }
#stats { grid-area: stats }
#board { grid-area: board }
#controls { grid-area: ctrls }
</style>
<div id="grid">
<div id="title">Game Title</div>
<div id="score">Score</div>
<div id="stats">Stats</div>
<div id="board">Board</div>
<div id="controls">Controls</div>
</div></pre>
<!--End Section: Source Independence--></div>
<div class=section id=grid-layering-of-elements>
<h3 id=grid-layering-of-elements0><span class=secno>2.4. </span>Grid
Layering of Elements</h3>
<div class=sidefigure>
<p> <img alt="Image: A control composed of layered HTML elements."
src="images/control-layering-and-alignment.png"></p>
<p class=caption>A control composed of layered HTML elements.</p>
</div>
<p> In the example shown in Figure 6, the author is creating a custom
slider control. The control has six parts. The lower and upper labels
align to the left and right edges of the control. The track of the
slider spans the area between the labels. The lower and upper fill parts
touch beneath the thumb, and the thumb is a fixed width and height that
can be moved along the track by updating the two fraction-sized columns.
</p>
<p> Prior to the <a href="#grid-element"><i>Grid element</i></a>, the
author would have likely used absolute positioning to control the top
and left coordinates, along with the width and height of each HTML
element that comprises the control. By leveraging the <a
href="#grid-element"><i>Grid element</i></a>, the author can instead
limit script usage to handling mouse events on the thumb, which snaps to
various positions along the track as the ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ property of the <a
href="#grid-element"><i>Grid element</i></a> is updated.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
/* The grid-definition-columns and rows properties also support naming grid lines */
/* which can then be used to position grid items. The line names are assigned on */
/* either side of a column or row sizing function where the line would logically exist. */
grid-definition-columns:
"start" auto
"track-start" 0.5fr
"thumb-start" auto
"fill-split" auto
"thumb-end" 0.5fr
"track-end" auto
"end";
}
/* grid-column and grid-row accept a starting and optional ending line. */
/* Below the lines are referred to by name. Beyond any semantic advantage, the names */
/* also allow the author to avoid renumbering the grid-row-position and */
/* column properties of the grid items. This is similar to the concept demonstrated in the */
/* prior example with the grid-template property during orientation changes, but */
/* grid lines can also work with layered grid items that have overlapping areas of */
/* different shapes like the thumb and track parts in this example. */
#lower-label { grid-column: "start" }
#track { grid-column: "track-start" "track-end"; align-self: center }
#upper-label { grid-column: "track-end"; }
/* Fill parts are drawn above the track so set z-index to 5. */
#lower-fill { grid-column: "track-start" "fill-split"; align-self: center; z-index: 5 }
#upper-fill { grid-column: "fill-split" "track-end"; align-self: center; z-index: 5 }
/* Thumb is the topmost part; assign it the highest z-index value. */
#thumb { grid-column: "thumb-start" "thumb-end"; z-index: 10 }
</style>
<div id="grid">
<div id="lower-label">Lower Label</div>
<div id="upper-label">Upper Label</div>
<div id="track">Track</div>
<div id="lower-fill">Lower Fill</div>
<div id="upper-fill">Upper Fill</div>
<div id="thumb">Thumb</div>
</div></pre>
<!--End Section: Grid Layering of Elements--></div>
<!--End Section: Introduction--></div>
<div class=section id=grid-concepts>
<h2 id=core-concepts-of-the-grid><span class=secno>3. </span>Core Concepts
of the Grid</h2>
<div class=sidefigure> <img
alt="Image: A diagram illustrating the relationship between the Grid Element and its Tracks, Lines, Areas and Items."
class=figure src="images/grid-concepts.png">
<p class=caption>A diagram illustrating the relationship between the <a
href="#grid-element"><i>Grid element</i></a> and its Tracks, Lines,
Areas and Items.</p>
</div>
<p> A <dfn id=grid-element>Grid element</dfn> is declared in markup by
setting the display property of an element to ‘<a href="#grid"><code
class=css>grid</code></a>’ or ‘<a href="#inline-grid"><code
class=css>inline-grid</code></a>’. Child elements of the Grid are
termed <a href="#grid-item"><i>Grid items</i></a> and may be positioned
and sized by the <a href="#grid-element"><i>Grid element</i></a> by
leveraging the following logical concepts.</p>
<ul>
<li><a href="#grid-track"><i>Grid tracks</i></a>
<li><a href="#grid-line"><i>Grid lines</i></a>
<li><a href="#grid-area-concept"><i>Grid areas</i></a>
</ul>
<p> Figure 7 illustrates the relationship between these concepts and the
markup in the subsections that follow produce the result shown in the
figure.</p>
<div class=section id=grid-concepts-tracks>
<h3 id=grid-tracks><span class=secno>3.1. </span>Grid Tracks</h3>
<p> <dfn id=grid-track>Grid Track</dfn>s are the columns and rows of the
Grid defined with the ‘<a href="#grid-definition-rows"><code
class=property>grid-definition-rows</code></a>’ and ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ properties on the
<a href="#grid-element"><i>Grid element</i></a>. Each Track is defined
by declaring a sequential list of sizing functions, one for each Track.
Tracks define the space between <a href="#grid-line"><i>Grid
lines</i></a>.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
grid-definition-columns: 150px 1fr; /* two columns */
grid-definition-rows: 50px 1fr 50px /* three rows */
}
</style></pre>
<!--End Section: Grid Tracks--></div>
<div class=section id=grid-concepts-lines>
<h3 id=grid-lines><span class=secno>3.2. </span>Grid Lines</h3>
<p> <dfn id=grid-line>Grid Line</dfn>s are the horizontal or vertical
dividing lines that exist on either side of a column or row. <a
href="#grid-line"><i>Grid lines</i></a> may be referred to by their <a
href="#grid-line"><i>Grid line</i></a> number, or they may be named by
the author. Authors use one or more quoted strings to assign names to a
<a href="#grid-line"><i>Grid line</i></a> before or after a <a
href="#grid-track"><i>Grid track</i></a> definition wherever the desired
<a href="#grid-line"><i>Grid line</i></a> would logically exist. A <a
href="#grid-item"><i>Grid item</i></a> then uses the <a
href="#grid-line"><i>Grid lines</i></a> to determine its position within
the Grid by referencing the <a href="#grid-line"><i>Grid lines</i></a>
using the properties ‘<a href="#grid-row-position"><code
class=property>grid-row-position</code></a>’ and ‘<a
href="#grid-column-position"><code
class=property>grid-column-position</code></a>’.</p>
<p> The following two examples create three column <a
href="#grid-line"><i>Grid lines</i></a> and four row <a
href="#grid-line"><i>Grid lines</i></a>. The first example demonstrates
how an author would position a <a href="#grid-item"><i>Grid item</i></a>
using <a href="#grid-line"><i>Grid line</i></a> numbers. The second
example uses explicitly named <a href="#grid-line"><i>Grid
lines</i></a>.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
grid-definition-columns: 150px 1fr;
grid-definition-rows: 50px 1fr 50px
}
#item1 { grid-column-position: 2; grid-row-position: 1; grid-row-span: 3 }
</style></pre>
<pre class=example><style type="text/css">
/* equivalent layout to the prior example, but using named lines */
#grid {
display: grid;
grid-definition-columns: 150px "item1-start" 1fr "item1-end";
grid-definition-rows: "item1-start" 50px 1fr 50px "item1-end"
}
#item1 {
grid-column: "item1-start" "item1-end";
grid-row: "item1-start" "item1-end"
}
</style></pre>
<!--End Section: Grid Lines--></div>
<div class=section id=grid-concepts-areas>
<h3 id=grid-areas><span class=secno>3.3. </span>Grid Areas</h3>
<p> <dfn id=grid-area-concept>Grid Area</dfn>s are the logical space used
to lay out one or more <a href="#grid-item"><i>Grid items</i></a>. <a
href="#grid-area-concept"><i>Grid areas</i></a> may be defined
explicitly using the ‘<a href="#grid-template"><code
class=property>grid-template</code></a>’ property, or implicitly by
referencing a region of the Grid using the properties ‘<a
href="#grid-row-position"><code
class=property>grid-row-position</code></a>’ and ‘<a
href="#grid-column-position"><code
class=property>grid-column-position</code></a>’ on a <a
href="#grid-item"><i>Grid item</i></a>.</p>
<p> Whether a <a href="#grid-area-concept"><i>Grid area</i></a> is
created explicitly or implicitly, there is no difference in the layout
or drawing order of the <a href="#grid-item"><i>Grid items</i></a> which
are associated with that <a href="#grid-area-concept"><i>Grid
area</i></a>. <a href="#grid-area-concept"><i>Grid areas</i></a> cannot
be styled. Only the syntax used to refer to a region of space on the
Grid differs between the implicit and explicit approach to provide
authors with the tools to best suit their scenarios as illustrated in
prior examples.</p>
<pre class=example><style type="text/css">
/* using the template syntax */
#grid {
display: grid;
grid-template: ". a"
"b a"
". a";
grid-definition-columns: 150px 1fr;
grid-definition-rows: 50px 1fr 50px
}
#item1 { grid-area: a }
#item2 { grid-area: b }
#item3 { grid-area: b }
/* Align items 2 and 3 at different points in the Grid Area "b". */
/* By default, Grid Items are stretched to fit their Grid Area */
/* and these items would layer one over the other. */
#item2 { align-self: head }
#item3 { justify-self: end; align-self: foot }</style></pre>
<!--End Section: Grid Areas--></div>
<!--End Section: Core Concepts of the Grid--></div>
<div class=section id=defining-the-grid>
<h2 id=defining-the-grid0><span class=secno>4. </span>Defining the Grid</h2>
<div class=section id=grid-declaration>
<h3 id=grid-declaration0><span class=secno>4.1. </span>Grid Declaration</h3>
<p> A <a href="#grid-element"><i>Grid element</i></a> is declared by
setting the display property.</p>
<table class=propdef id=display-property>
<tbody>
<tr>
<td>Name:
<td>display
<tr>
<td>Value:
<td> [ ...existing values... | <dfn id=grid>grid</dfn> | <dfn
id=inline-grid>inline-grid</dfn> |
<tr>
<td>Computed value:
<td>specified value
</table>
<dl>
<dt><a name=value-def-display-grid>grid</a>
<dd>A value of grid causes an element to display as a block-level <a
href="#grid-element"><i>Grid element</i></a>.
<dt><a name=value-def-display-inline-grid>inline-grid</a>
<dd>A value of inline-grid causes an element to display as an
inline-level <a href="#grid-element"><i>Grid element</i></a>.
</dl>
<p>The baseline of an inline <a href="#grid-element"><i>Grid
element</i></a> is the bottom edge of the margin box.</p>
<!--End Section: Grid Declaration--></div>
<div class=section id=grid-rows-and-columns>
<h3 id=grid-rows-and-columns0><span class=secno>4.2. </span>Grid Rows and
Columns</h3>
<div class=sidefigure> <img alt="Image: Grid Lines." class=figure
src="images/grid-lines.png">
<p class=caption>Grid Lines.</p>
</div>
<p> <a href="#grid-element"><i>Grid elements</i></a> use <a
href="#grid-line"><i>Grid lines</i></a> to divide their space. There are
two sets of <a href="#grid-line"><i>Grid lines</i></a>: one set defined
by the columns that run in the direction of block progression, and
another orthogonal set defined by rows. Block progression is a
writing-mode term that defines a logical direction. In English it means
vertical.</p>
<p> A <a href="#grid-track"><i>Grid track</i></a> is a generic term for a
column or row which separates two <a href="#grid-line"><i>Grid
lines</i></a>. Each <a href="#grid-track"><i>Grid track</i></a> is
assigned a sizing function, which controls how wide or tall the column
or row may grow, and thus how far apart two <a href="#grid-line"><i>Grid
lines</i></a> are. The sizing function specified can be a length, a
percentage of the <a href="#grid-element"><i>Grid element</i></a>’s
size, derived from the contents occupying the column or row, or a
proportion of the space which remains in the <a
href="#grid-element"><i>Grid element</i></a>. In the last case,
remaining space refers to the width or height of the <a
href="#grid-element"><i>Grid element</i></a> after accounting for space
already consumed by columns and rows sized with a length, percentage or
content. The size can also be specified as a range using a minmax
function, which can combine any of the previously mentioned mechanisms
to define a min and max size for the column or row.</p>
<p> In the following example there are two columns and three rows. The
first column is 150px wide beginning from the starting edge of the <a
href="#grid-element"><i>Grid element</i></a>’s content box. The second
column uses fractional sizing, which is a function of the remaining
space in the Grid. Its size will vary as the width of the <a
href="#grid-element"><i>Grid element</i></a> changes. If the used width
of the <a href="#grid-element"><i>Grid element</i></a> is 200px, then
the second column 50px wide. If the used width of the <a
href="#grid-element"><i>Grid element</i></a> is 100px, then the second
column is 0px and any content positioned in the column will be
overflowing the <a href="#grid-element"><i>Grid element</i></a>. Sizing
occurs in a similar fashion for the rows.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
grid-definition-columns: 150px 1fr;
grid-definition-rows: 50px 1fr 50px
}
</style></pre>
<!--End Section: Grid Rows, Columns and Implicit Grid Lines--></div>
<div class=section id=grid-named-grid-lines>
<h3 id=named-grid-lines><span class=secno>4.3. </span>Named Grid Lines</h3>
<div class=sidefigure> <img alt="Image: Named Grid Lines." class=figure
src="images/grid-named-lines.png">
<p class=caption>Named Grid Lines.</p>
</div>
<p> A <a href="#grid-line"><i>Grid line</i></a> exists on either side of
a column or row. The <a href="#grid-line"><i>Grid line</i></a> may be
named using one or more quoted strings which are positioned in the ‘<a
href="#grid-definition-rows"><code
class=property>grid-definition-rows</code></a>’ or ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ definitions where
the <a href="#grid-line"><i>Grid line</i></a> would logically occur (in
between the sizing functions that define the Grid's columns and rows).
Each name associated with a <a href="#grid-line"><i>Grid line</i></a>
must be unique for the set of columns or rows. If the name is specified
multiple times in the same column or row definition, it is associated
with the first <a href="#grid-line"><i>Grid line</i></a> to which the
name was assigned. When a name is not specified, <a
href="#grid-line"><i>Grid lines</i></a> can be referred to in the order
which they occur. The first line is 1, the second 2 and so on. The next
example builds on the prior by assigning each line one or more names.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
grid-definition-columns: "first" "nav" 150px "main" 1fr "last";
grid-definition-rows: "first" "header" 50px "main" 1fr "footer" 50px "last";
}
</style></pre>
<!--End Section: Named Grid Lines--></div>
<div class=section id=grid-repeating-columns-and-rows>
<h3 id=repeating-columns-and-rows><span class=secno>4.4. </span>Repeating
Columns and Rows</h3>
<p> If there are large number of columns or rows that are the same or
exhibit a recurring pattern, a repeat function can be applied to define
the columns or rows in a more compact form.</p>
<p> The next two examples are equivalent. There is a single row, and a
pattern of repetitive column <a href="#grid-line"><i>Grid lines</i></a>:
a 250px column followed by a 10px column. Note that when the repeat
function is used with <a href="#grid-line"><i>Grid line</i></a> naming,
that the names are assigned to the first occurrence of the pattern.</p>
<pre class=example><style type="text/css">
#grid {
display: grid;
grid-definition-columns: 10px "content" 250px 10px 250px 10px 250px 10px 250px 10px;
grid-definition-rows: 1fr;
}
/* Equivalent definition. */
#grid {
display: grid;
grid-definition-columns: 10px repeat(4, "content" 250px 10px);
grid-definition-rows: 1fr;
}
</style></pre>
<!--End Section: Repeating Columns and Rows--></div>
<div class=section id=grid-definition-columns-and-rows-properties>
<h3 id=grid-definition-columns-and-grid-definit><span class=secno>4.5.
</span>Grid-definition-columns and Grid-definition-rows Properties</h3>
<p> The following grammar expresses the allowable values for the ‘<a
href="#grid-definition-rows"><code
class=property>grid-definition-rows</code></a>’ and ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ properties.</p>
<code></code>
<pre><track-list> => [ [ <string> ]* <track-group> [ <string> ]* ]+ | none
<track-group> => <track-minmax> | [ repeat( <positive-integer> , [ [ <string> ]* <track-minmax> [ <string> ]* ]+ ) ]
<track-minmax> => minmax( <track-breadth> , <track-breadth> ) | auto | <track-breadth>
<track-breadth> => <length> | <percentage> | <fraction> | min-content | max-content</pre>
<br>
<p>Where:</p>
<ul>
<li><dfn id=length>length</dfn> is as defined by CSS3 Values. <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>