-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.src.html
More file actions
executable file
·2445 lines (2263 loc) · 141 KB
/
Overview.src.html
File metadata and controls
executable file
·2445 lines (2263 loc) · 141 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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<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>
</head>
<body>
<div class="head">
<!--logo-->
<h1 class="title" id="title">CSS Grid Layout</h1>
<h2 class="no-num no-toc">[LONGSTATUS], [DATE: 3 March 2012]</h2>
<dl>
<dt>This version:</dt>
<!-- <dd><a href="[VERSION]">http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]/</a> -->
<dd><a href="http://dev.w3.org/csswg/css3-grid-layout/">http://dev.w3.org/csswg/css3-grid-layout/</a>
<dt>Latest version:</dt><dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a>
<dt>Editor's draft:</dt><dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
<dt>Previous version</dt><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></dd>
<dt>Issues List:</dt>
<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:</dt>
<dd><a href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a> with subject line “<kbd>[[SHORTNAME]] <var>… message topic …</var></kbd>”
<dt>Editors:</dt>
<dd><a href="mailto:alexmog@microsoft.com">Alex Mogilevsky</a>, Microsoft Corporation</dd>
<dd><a href="mailto:pcupp@microsoft.com">Phil Cupp</a>, Microsoft Corporation</dd>
<dd><a href="mailto:mmielke@microsoft.com">Markus Mielke</a>, Microsoft Corporation</dd>
<dd><a href="mailto:daniel.glazman@disruptive-innovations.com">Daniel Glazman</a>, Disruptive Innovations</dd>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc">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 <i>Grid lines</i> 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">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>
<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>
<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 rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/32061/status">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>
<h2 class="no-num no-toc" id="table">Table of contents</h2>
<!--toc-->
<div id="dependencies" class="section">
<h2>Dependencies on other modules</h2>
<p>
This CSS3 module has normative references to the following other CSS3 modules:
</p>
<ul>
<li>[[!CSS3VAL]]</li>
<li>[[!CSS3-ALIGN]]</li>
<li>[[!CSS3VAL]]</li>
</ul>
<p>
This CSS3 module has non-normative (informative) references to the following other CSS3 modules:
</p>
<ul>
<li>[[CSS3LAYOUT]]</li>
</ul>
</div>
<!--End section: Dependencies -->
<div id="Introduction" class="section">
<h2>Introduction</h2>
<div id="basic-capabilities" class="section">
<h3>Basic Capabilities of the Grid</h3>
<div class="sidefigure">
<img class="figure" alt="Image: Application layout example requiring horizontal and vertical alignment." 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 <i>Grid lines</i> between the columns and rows, or by defining and referencing a <i>Grid area</i>, 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 id="adapting-to-available-space" class="section">
<h3>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 <i>Grid element</i> 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:
</p><ul>
<li>The stats area always appears immediately under the game title.</li>
<li>The game board appears to the right of the stats and title.</li>
<li>The top of the game title and the game board should always align.</li>
<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>
<li>The score area should align into the column created by the game and stats area, while the controls are centered under the board.</li>
</ul>
<p>
As an alternative to using script to control the absolute position, width, and height of all elements, the author can use the <i>Grid element</i>, 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 <i>Grid element</i> and to position and size <i>Grid items</i>, each optimized for different scenarios.
This example illustrates one that an author may use to define the position and space for each <i>Grid item</i> using the
'grid-definition-rows' and 'grid-definition-columns' properties of the <i>Grid element</i>,
and the 'grid-row-position', 'grid-column-position', 'grid-row-span' and 'grid-column-span' properties on each <i>Grid item</i>.
</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>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 ''portrait'' orientation.</p>
</div>
<div class="sidefigure">
<p>
<img alt="Image: An arrangement suitable for landscape orientation." src="images/game-landscape.png" />
</p>
<p class="caption">An arrangement suitable for ''landscape'' 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 <i>Grid element</i> 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 <i>Grid element</i>’s ability to name the space which will be occupied by a <i>Grid item</i>. This allows the author
to avoid rewriting rules for <i>Grid items</i> as the <i>Grid element</i>’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>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 <i>Grid element</i>, 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 <i>Grid element</i>, the author can instead limit script usage to handling mouse events on the thumb,
which snaps to various positions along the track as the 'grid-definition-columns' property of the <i>Grid element</i> 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 id="grid-concepts" class="section">
<h2>Core Concepts of the Grid</h2>
<div class="sidefigure">
<img class="figure" alt="Image: A diagram illustrating the relationship between the Grid Element and its Tracks, Lines, Areas and Items." src="images/grid-concepts.png" />
<p class="caption">A diagram illustrating the relationship between the <i>Grid element</i> 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 ''grid'' or ''inline-grid''. Child elements of the Grid are termed <i>Grid items</i> and may be positioned and sized by the <i>Grid element</i> by leveraging the following logical concepts.
</p>
<ul>
<li><i>Grid tracks</i></li>
<li><i>Grid lines</i></li>
<li><i>Grid areas</i></li>
</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 id="grid-concepts-tracks" class="section">
<h3>Grid Tracks</h3>
<p>
<dfn id="grid-track">Grid Track</dfn>s are the columns and rows of the Grid defined with the 'grid-definition-rows' and 'grid-definition-columns' properties on the <i>Grid element</i>. Each Track is defined by declaring a sequential list of sizing functions, one for each Track. Tracks define the space between <i>Grid lines</i>.
</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 id="grid-concepts-lines" class="section">
<h3>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. <i>Grid lines</i> may be referred to by their <i>Grid line</i> number, or they may be named by the author. Authors use one or more quoted strings to assign names to a <i>Grid line</i> before or after a <i>Grid track</i> definition wherever the desired <i>Grid line</i> would logically exist. A <i>Grid item</i> then uses the <i>Grid lines</i> to determine its position within the Grid by referencing the <i>Grid lines</i> using the properties 'grid-row-position' and 'grid-column-position'.
</p>
<p>
The following two examples create three column <i>Grid lines</i> and four row <i>Grid lines</i>. The first example demonstrates how an author would position a <i>Grid item</i> using <i>Grid line</i> numbers. The second example uses explicitly named <i>Grid lines</i>.
</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 id="grid-concepts-areas" class="section">
<h3>Grid Areas</h3>
<p>
<dfn id="grid-area-concept">Grid Area</dfn>s are the logical space used to lay out one or more <i>Grid items</i>. <i>Grid areas</i> may be defined explicitly using the 'grid-template' property, or implicitly by referencing a region of the Grid using the properties 'grid-row-position' and 'grid-column-position' on a <i>Grid item</i>.
</p>
<p>
Whether a <i>Grid area</i> is created explicitly or implicitly, there is no difference in the layout or drawing order of the <i>Grid items</i> which are associated with that <i>Grid area</i>. <i>Grid areas</i> 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>Defining the Grid</h2>
<div id="grid-declaration" class="section">
<h3>Grid Declaration</h3>
<p>
A <i>Grid element</i> is declared by setting the display property.
</p>
<table id="display-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td>display</td>
</tr>
<tr>
<td>Value:</td>
<td>
[ ...existing values... | <dfn id="grid">grid</dfn> | <dfn id="inline-grid">inline-grid</dfn> |
</td>
</tr>
<tr>
<td>Computed value:</td>
<td>specified value</td>
</tr>
</tbody>
</table>
<dl>
<dt><a name="value-def-display-grid">grid</a></dt>
<dd>A value of grid causes an element to display as a block-level <i>Grid element</i>.</dd>
<dt><a name="value-def-display-inline-grid">inline-grid</a></dt>
<dd>A value of inline-grid causes an element to display as an inline-level <i>Grid element</i>.</dd>
</dl>
<p>The baseline of an inline <i>Grid element</i> is the bottom edge of the margin box.</p>
<!--End Section: Grid Declaration-->
</div>
<div class="section" id="grid-rows-and-columns">
<h3>Grid Rows and Columns</h3>
<div class="sidefigure">
<img class="figure" alt="Image: Grid Lines." src="images/grid-lines.png" />
<p class="caption">Grid Lines.</p>
</div>
<p>
<i>Grid elements</i> use <i>Grid lines</i> to divide their space. There are two sets of <i>Grid lines</i>: 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 <i>Grid track</i> is a generic term for a column or row which separates two <i>Grid lines</i>. Each <i>Grid track</i> is assigned a sizing function, which controls how wide or tall the column or row may grow, and thus how far apart two <i>Grid lines</i> are. The sizing function specified can be a length, a percentage of the <i>Grid element</i>’s size, derived from the contents occupying the column or row, or a proportion of the space which remains in the <i>Grid element</i>. In the last case, remaining space refers to the width or height of the <i>Grid element</i> 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 <i>Grid element</i>’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 <i>Grid element</i> changes. If the used width of the <i>Grid element</i> is 200px, then the second column 50px wide. If the used width of the <i>Grid element</i> is 100px, then the second column is 0px and any content positioned in the column will be overflowing the <i>Grid element</i>. 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>Named Grid Lines</h3>
<div class="sidefigure">
<img class="figure" alt="Image: Named Grid Lines." src="images/grid-named-lines.png" />
<p class="caption">Named Grid Lines.</p>
</div>
<p>
A <i>Grid line</i> exists on either side of a column or row. The <i>Grid line</i> may be named using one or more quoted strings which are positioned in the 'grid-definition-rows' or 'grid-definition-columns' definitions where the <i>Grid line</i> would logically occur (in between the sizing functions that define the Grid's columns and rows). Each name associated with a <i>Grid line</i> 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 <i>Grid line</i> to which the name was assigned. When a name is not specified, <i>Grid lines</i> 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>
<p class="issue">
Consider merging grid line names with grid field names. See: <a href="http://lists.w3.org/Archives/Public/www-style/2012Sep/0047.html">http://lists.w3.org/Archives/Public/www-style/2012Sep/0047.html</a> for proposal.
</p>
<!--End Section: Named Grid Lines-->
</div>
<div class="section" id="grid-repeating-columns-and-rows">
<h3>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 <i>Grid lines</i>: a 250px column followed by a 10px column. Note that when the repeat function is used with <i>Grid line</i> 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>Grid-definition-columns and Grid-definition-rows Properties</h3>
<p>
The following grammar expresses the allowable values for the 'grid-definition-rows' and 'grid-definition-columns' properties.
</p>
<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></code>
<br>
<p>Where:</p>
<ul>
<li><dfn id="length">length</dfn> is as defined by CSS3 Values. [[!CSS3VAL]]</li>
<li><i>percentage</i> expresses a size for a <i>Grid track</i> as a percentage of the <i>Grid element</i>’s logical width (for columns) or logical height (for rows).
When the width or height of the <i>Grid element</i> is dependent on content, the result is undefined.</li>
<li><dfn id="fraction">fraction</dfn> is a non-negative floating-point number followed
by 'fr'. Each 'fraction' value takes a share of the remaining space proportional to
its number. See <i>fraction values</i> for more details.</li>
<li><dfn id="max-content">max-content</dfn> is a keyword which refers to the maximum of the max sizes of <i>Grid items</i> occupying
the <i>Grid track</i>.</li>
<li><dfn id="min-content">min-content</dfn> is a keyword which refers to the maximum of the min sizes of <i>Grid items</i> occupying
the <i>Grid track</i>.</li>
<li><dfn id="minmax">minmax(min, max)</dfn> defines a size range. The size used
should be greater than or equal to 'min' and less than or equal to 'max'. If 'max' < 'min',
then 'max' is ignored and 'minmax(min,max)' is treated as 'minmax(min,min)'.</li>
<li><dfn id="auto">auto</dfn> is equivalent to 'minmax(min-content, max-content)'.</li>
</ul>
<p class="issue">
Consider whether having undefined behavior for percentage-sized tracks in content-sized grids is appropriate. CSS2.1 and CSS3 leave percentage width undefined, although there appears to be consistency between browser implementations.
</p>
<p class=issue>
The current property names imply a grid model more akin to tables than a traditional design grid.
Consider adjusting terminology to focus on grid lines rather than the spaces between the lines.
</p>
<br>
<table id="grid-definition-columns-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-definition-columns">grid-definition-columns</dfn></td>
</tr>
<tr>
<td>Value:</td>
<td>see grammar above</td>
</tr>
<tr>
<td>Initial:</td>
<td>none</td>
</tr>
<tr>
<td>Applies to:</td>
<td>non-replaced elements with a computed value of ''grid'' or ''inline-grid'' for display.</td>
</tr>
<tr>
<td>Inherited:</td>
<td>no</td>
</tr>
<tr>
<td>Percentages:</td>
<td>n/a</td>
</tr>
<tr>
<td>Media:</td>
<td>visual, paged</td>
</tr>
<tr>
<td>Computed value:</td>
<td>see text</td>
</tr>
</tbody>
</table>
<table id="grid-definition-rows-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-definition-rows">grid-definition-rows</dfn></td>
</tr>
<tr>
<td>Value:</td>
<td>see grammar above</td>
</tr>
<tr>
<td>Initial:</td>
<td>none</td>
</tr>
<tr>
<td>Applies to:</td>
<td>non-replaced elements with a computed value of ''grid'' or ''inline-grid'' for display.</td>
</tr>
<tr>
<td>Inherited:</td>
<td>no</td>
</tr>
<tr>
<td>Percentages:</td>
<td>n/a</td>
</tr>
<tr>
<td>Media:</td>
<td>visual, paged</td>
</tr>
<tr>
<td>Computed value:</td>
<td>see text</td>
</tr>
</tbody>
</table>
<p>The following example:</p>
<ul>
<li>Adds one <i>Grid line</i> 100 pixels from the starting edge of the grid.</li>
<li>Adds another <i>Grid line</i> 1/2 of the remaining space away.</li>
<li>Adds another <i>Grid line</i> whose distance from the prior <i>Grid line</i> will be based on the maximum content size of elements
occupying the column.</li>
<li>Adds another <i>Grid line</i> whose distance from the prior <i>Grid line</i> is based on
the minimum content size of all elements occupying the column, or 1/2 the
remaining space, whichever is greater.</li>
</ul>
<pre class="example">div { grid-definition-columns: 100px 1fr max-content minmax(min-content, 1fr) }</pre>
<p>Additional examples of valid <i>Grid track</i> definitions:</p>
<pre class="example"> /* examples of valid track definitions */
grid-definition-rows: 1fr minmax(min-content, 1fr);
grid-definition-rows: 10px repeat(2, 1fr auto minmax(30%, 1fr));
grid-definition-rows: (10px);
grid-definition-rows: calc(4em - 5px)</pre>
<!--End Section: grid-definition-columns and grid-definition-rows Properties-->
</div>
<div id="fraction-values-fr" class="section">
<h4>Fraction Values: 'fr'</h4>
<p><dfn id="fraction-values">Fraction values</dfn> are new units applicable to the 'grid-definition-rows' and 'grid-definition-columns' properties:</p>
<dl>
<dt>fr</dt>
<dd>Fraction of available space. </dd>
</dl>
<p>
The distribution of fractional space occurs after all ''length''
or content-based row and column sizes have reached their maximum.
The total size of the rows or columns is then subtracted from the available space and the remainder is
divided proportionately among the fractional rows and columns.
</p>
<p>
Each column or row's proportional share can be computed as the column or row's
<code><fraction> * <remaining space> / <sum of all fractions></code>.
Note that fractions occurring within a ''minmax'' function are only counted in the sum if in the ''max'' position.
Further, fractions that occur in the ''min'' position are treated as an absolute length of <code>0px</code>.
</p>
<p>
When remaining space cannot be determined because the width or height of the <i>Grid element</i> is undefined, fraction-sized <i>Grid tracks</i>
are sized to their contents while retaining their respective proportions. In such cases the size of each fractional <i>Grid track</i> can
be computed by determining the 'max-content' size of each fractional <i>Grid track</i> and dividing that size by the respective
'fraction'. The maximum value of those results is treated as the <code>1fr</code> value, which is then multiplied
by each <i>Grid track</i>’s 'fraction' to determine its final size.
</p>
<!--End Section: Fraction Values: 'fr'-->
</div>
<div id="used-values-grid-rows-and-columns" class="section">
<h4>Used Values for grid-definition-rows and grid-definition-columns</h4>
<p>
The used size of all <i>Grid tracks</i> as returned for the 'grid-definition-rows' and 'grid-definition-columns' properties are normalized to pixel values.
All <i>Grid tracks</i> are included in the used value reported for 'grid-definition-rows' and 'grid-definition-columns' regardless of how the <i>Grid tracks</i> were created, e.g. implicit tracks may be created by <i>Grid items</i> referencing a <i>Grid line</i> not explicitly defined by a 'grid-definition-rows' or 'grid-definition-columns' property.
The used value includes named lines; any duplicate names must be removed. User agents may use the repeat syntax to avoid expansive string length due to implicit <i>Grid track</i> creation,
large spanning values or high repeat counts specified by the author.
</p>
<p>
The algorithm used to apply repeat syntax to used <i>Grid track</i> values and <i>Grid line</i> names is user agent specific. See below for example inputs and outputs.
</p>
<pre class="example"><style type="text/css">
#grid {
width: 500px;
grid-definition-columns:
"a" auto
"b" minmax(min-content, 1fr)
"b" "c" "d" repeat(2, "e" 40px)
repeat(5, auto);
}
</style>
<div id="grid">
<div style="grid-column-position:1; width:50px"></div>
<div style="grid-column-position:9; width:50px"></div>
</div>
<script type="text/javascript">
// Returns '"a" 50px "b" 320px "c" "d" repeat(2, "e" 40px) repeat(4, 0px) 50px'.
var gridElement = document.getElementById("grid");
window.getComputedStyle(gridElement, null).getPropertyValue("grid-definition-columns");
</script></pre>
<!--End Section: used-values-grid-rows-and-columns -->
</div>
<div id="defining-grid-areas-with-a-template" class="section">
<h3>Defining Grid Areas with a Template</h3>
<p>
<i>Grid areas</i> can also be defined explicitly using <a href="http://www.w3.org/TR/css3-syntax/Overview.html#identifiers">identifiers</a> via the 'grid-template' property. The 'grid-template' property provides a visualization of the <i>Grid element</i>’s structure while simultaneously defining the <i>Grid areas</i> which can be used to position and size the child elements of the Grid.
</p>
<p>
A row is created for every separate string listed for the grid-template property, and a column is created for each identifier or period in each string. Note that all strings must have the same number of columns. A period represents an unnamed area in the <i>grid element</i> that cannot be used to position or size a <i>grid item</i>. An identifier creates a named <i>grid area</i> that can be used to position and size <i>grid items</i>. No two <i>grid areas</i> may have the same identifier. Duplicate identifiers define a <i>grid area</i> which spans multiple tracks, and must therefore be geometrically adjacent to each other, forming a rectangular shape. A declaration which fails to meet these criteria will be dropped.
</p>
<p>
In the following example, a 'grid-template' property is used to create a page layout where areas are defined for header content <code>head</code>, navigational content <code>nav</code>, footer content <code>foot</code>, and main content <code>main</code>. Accordingly, the template creates three rows, two columns, and four areas. The <code>head</code> area spans both columns and the first row of the grid. Columns are the tracks that run in the inline direction and rows are the tracks running in the direction of block progression. See Grid Writing Modes for more details.
</p>
<p>
The 'grid-area' property, defined in further detail below, is specified on <i>Grid items</i> to position the <i>Grid item</i> inside an explicitly named <i>Grid area</i>.
The 'grid-area' property, defined in further detail below, is specified on <i>Grid items</i> to position the <i>Grid item</i> inside an explicitly named <i>Grid area</i>.
</p>
<pre class="example"><style type="text/css">
#grid {
display: grid;
grid-template: "head head"
"nav main"
"foot ."
}
#grid > a {
grid-area: "nav";
}
</style></pre>
<table id="grid-template-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-template">grid-template</dfn></td>
</tr>
<tr>
<td>Value:</td>
<td>[ " [ <identifier> | . ]+ " ]+ | <dfn id="none-template">none</dfn></td>
</tr>
<tr>
<td>Initial:</td>
<td>none</td>
</tr>
<tr>
<td>Applies to:</td>
<td>Grid elements</td>
</tr>
<tr>
<td>Inherited:</td>
<td>no</td>
</tr>
<tr>
<td>Percentages:</td>
<td>n/a</td>
</tr>
<tr>
<td>Media:</td>
<td>visual, paged</td>
</tr>
<tr>
<td>Computed value:</td>
<td>specified value</td>
</tr>
</tbody>
</table>
<!--End Section: Defining Grid Areas with a Template-->
</div>
<!--End Section: Defining the Grid-->
</div>
<div id="grid-items" class="section">
<h2>Grid items</h2>
<p>
The contents of a <i>grid element</i> consists of zero or more <dfn id="grid-item">grid item</dfn>s:
each child of a <i>grid element</i>
becomes a <i>grid item</i>,
and each contiguous run of text that is directly contained inside a <i>grid element</i>
is wrapped in an anonymous <i>grid item</i>.
However, an anonymous grid item that contains only
<a href="http://www.w3.org/TR/CSS21/text.html#white-space-prop">white space</a>
is not rendered, as if it were ''display:none''.
<div class="issue">
This will place all of the contents of the grid on top of each other in slot 1 1.
Alternatives:
<ul>
<li>Turn on auto-positioning by default (see 'grid-auto-flow').
<li>Place all unpositioned elements in the grid into an anonymous grid item in slot 1 1.
<li>Place all unpositioned elements in the grid into an anonymous grid item whose position is given by a "*" template slot,
else is in slot 1 1.
<li>Same as the previous, except if there is no "*" template slot, auto-position the children.
</ul>
</div>
<p>
A <i>grid item</i> establishes a new formatting context for its contents.
The type of this formatting context is determined by its 'display' value, as usual.
The computed 'display' of a <i>grid item</i>
is determined by applying the table in
<a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter 9.7</a>.
However, grid items are grid-level boxes, not block-level boxes:
they participate in the <i>grid element</i>’s formatting context,
not in a block formatting context.
<div class="example">
<p>Examples of grid items:
<pre>
<div style="display:grid">
<!-- grid item: block child -->
<div id="item1">block</div>
<!-- grid item: floated element; floating is ignored -->
<div id="item2" style="float: left;">float</div>
<!-- grid item: anonymous block box around inline content -->
anonymous item 3
<!-- grid item: inline child -->
<span>
item 4
<!-- grid items do not split around blocks -->
<div id=not-an-item>item 4</div>
item 4
</span>
</div></pre>
</div>
<p>
Some values of 'display' trigger the generation of anonymous boxes.
For example, a misparented ''table-cell'' child is fixed up
by <a href="http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes">generating anonymous ''table'' and ''table-row'' elements</a> around it. [[!CSS21]]
This fixup must occur <em>before</em> a grid element's children are promoted to <i>grid items</i>.
For example, given two contiguous child elements with ''display:table-cell'',
an anonymous table wrapper box around them becomes the <i>grid item</i>.
<p class='note'>
Future display types may generate anonymous containers (e.g. ruby) or otherwise mangle the box tree (e.g. run-ins).
It is intended that grid item determination run after these operations.
<h3>Grid-descendant Items</h3>
<p class="issue">
This is a proposal to create the ability to have descendants of a grid item participate in a grid layout,
similar to the behavior defined by the Template Layout module.
<p>A descendant of the grid can be pulled out of flow and participate directly in the grid
by assigning it ''position: grid''.
An element with ''position: grid'' is pulled out of flow and participates as a grid item
belonging to the first ancestor with ''display: grid''.
If the element is positioned using named lines or slots,
it belongs to the first ancestor with ''display: grid'' that has all of the corresponding named lines/slots.
If no such ancestor exists, the item remains in flow.
<p class="issue">
Alternatively, the item can just go into the first grid,
and missing names are treated as ''auto''.
<h3>Subgrids</h3>
<p class="issue">
This is a proposal to address the alignment of sub-items across grid items
<p>A grid item can itself be a grid element by giving it ''display: grid'';
in this case the layout of its contents will be independent of the layout
of the grid it participates in.
<p>
In some cases it might be necessary for the contents of multiple grid items
to align to each other; in this case ''display: subgrid'' can be used.
A grid item with ''display: subgrid'' behaves just like one with ''display: grid'' except that:
<ul>
<li>
The 'grid-column-definition' and 'grid-row-definition' properties do not apply.
Instead the number of explicit tracks is given by its 'grid-column-span' and 'grid-row-span' properties,
and their sizes are determined by the parent grid.
<li>
The used 'grid-column-span' and 'grid-row-span' of the item is determined by
the number of grid rows and grid columns it contains.
<li>
Its own grid items participate in the sizing of its parent grid and are aligned to it.
In this process, the sum of the item's margin, padding, and borders are applied as an extra layer of margin
to the items at those edges.
</ul>
<div class="example">
<p>For example, suppose we have a form consisting of a list of inputs with labels:
<pre>
<ul>
<li><label>Name:</label> <input name=fn>
<li><label>Address:</label> <input name=address>
<li><label>Phone:</label> <input name=phone>
</ul></pre>
<p>
We want the labels and inputs to align, and we want to style each list item with a border.
This can be accomplished with subgrid layout:
<pre>
ul {
display: grid;
grid-auto-flow: rows;
grid-definition-columns: auto 1fr;
}
li {
display: subgrid;
margin: 0.5em;
border: solid;
padding: 0.5em;
}
label {
grid-column: 1;
}
input {
grid-column: 2;
}</pre>
<!--End Section: Grid Items-->
</div>
<div id="grid-item-placement" class="section">
<h2>Placing Grid Items</h2>
<p>The properties 'grid-row-position' and 'grid-column-position' are used to place <i>Grid items</i> in the Grid. Numbers and strings refer to <i>Grid lines</i>. A value of ''auto'' will result in the placement of the <i>Grid item</i> according to the automatic placement algorithm described below. An <identifier> refers to a named <i>Grid area</i> and will compute to the <i>Grid line</i> associated with the starting edge of the <i>Grid area</i>. 'grid-row-position' and 'grid-column-position' properties that refer to an undefined <i>Grid line</i> or an undefined <i>Grid area</i> via an <identifier> will compute to their initial values.</p>
<p class="issue">Rather than using properties of "column" and "row" and associated spanning behavior, consider a grid item placement syntax based on identifying the bounding grid lines. See: <a href="http://lists.w3.org/Archives/Public/www-style/2012Sep/0047.html">http://lists.w3.org/Archives/Public/www-style/2012Sep/0047.html</a> for proposal.</p>