-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.src.html
More file actions
2234 lines (2102 loc) · 131 KB
/
Overview.src.html
File metadata and controls
2234 lines (2102 loc) · 131 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 profile="http://www.w3.org/2006/03/hcard">
<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="http://dev.w3.org/csswg/css3-grid-align/">http://dev.w3.org/csswg/css3-grid-align/</a></dd>
<dt>Latest published version:</dt><dd><a href="http://www.w3.org/TR/css3-grid-layout">http://www.w3.org/TR/css3-grid-layout</a></dd>
<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>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>
<section 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>
</section>
<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-->
<section 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-WRITING-MODES]]</li>
</ul>
<p>
This CSS3 module has non-normative (informative) references to the following other CSS3 modules:
</p>
<ul>
<li>[[CSS3LAYOUT]]</li>
</ul>
</section>
<!--End section: Dependencies -->
<section id="Introduction" class="section">
<h2>Introduction</h2>
<section 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 cell</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-->
</section>
<section 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-rows' and 'grid-columns' properties of the <i>Grid element</i>,
and the 'grid-row', 'grid-column', 'grid-row-span' and 'grid-column-span' properties on each <i>Grid item</i>.
</p>
<pre class="example"><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-columns: 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-rows: 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: 1; grid-row: 1 }
#score { grid-column: 1; grid-row: 3 }
#stats { grid-column: 1; grid-row: 2; grid-row-align: start }
#board { grid-column: 2; grid-row: 1; grid-row-span: 2 }
#controls { grid-column: 2; grid-row: 3; grid-column-align: 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-->
</section>
<section 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 arrangment suitable for landscape orientation." src="images/game-landscape.png" />
</p>
<p class="caption">An arrangment 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 cells of the grid are defined visually using the */
/* grid-template property. Each string is a row, and each letter a cell. */
/* The max number of letters in any one string determines the number of */
/* columns. */
grid-template: "ta"
"sa"
"bb"
"cc";
/* Columns and rows created with the template property can be assigned a sizing */
/* function with the grid-columns and grid-rows properties. */
grid-columns: auto minmax(min-content, 1fr);
grid-rows: auto auto minmax(min-content, 1fr) auto
}
}
@media (orientation: landscape) {
#grid {
display: grid;
/* Again the template property defines cells of the same name, but this time */
/* positioned differently to better suit a landscape orientation. */
grid-template: "tb"
"ab"
"sc";
grid-columns: auto minmax(min-content, 1fr);
grid-rows: auto minmax(min-content, 1fr) auto
}
}
/* The grid-cell property places a grid item into named region (cell) of the grid. */
#title { grid-cell: "t" }
#score { grid-cell: "s" }
#stats { grid-cell: "a" }
#board { grid-cell: "b" }
#controls { grid-cell: "c" }
</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-->
</section>
<section 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-columns' property of the <i>Grid element</i> is updated.
</p>
<pre class="example"><style type="text/css">
#grid {
display: grid;
/* The grid-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-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 endling 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 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 cells of different shapes like the thumb and track parts */
/* in this example. */
#lower-label { grid-column: "start" }
#track { grid-column: "track-start" "track-end"; grid-row-align: 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"; grid-row-align: center; z-index: 5 }
#upper-fill { grid-column: "fill-split" "track-end"; grid-row-align: 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-->
</section>
<!--End Section: Introduction-->
</section>
<section 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, Cells 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, Cells 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 cells</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>
<section 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-rows' and 'grid-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-columns: 150px 1fr; /* two columns */
grid-rows: 50px 1fr 50px /* three rows */
}
</style></pre>
<!--End Section: Grid Tracks-->
</section>
<section 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 and available space within the Grid by referencing the <i>Grid lines</i> using the properties 'grid-row' and 'grid-column'. 'grid-row' and 'grid-column' accept a starting and optional ending Line.
</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 refer to the <i>Grid lines</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-columns: 150px 1fr;
grid-rows: 50px 1fr 50px
}
#item1 { grid-column: 2; grid-row: 1 4 }
</style></pre>
<pre class="example"><style type="text/css">
/* equivalent layout to the prior example, but using named lines */
#grid {
display: grid;
grid-columns: 150px "item1-start" 1fr "item1-end";
grid-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-->
</section>
<section id="grid-concepts-cells" class="section">
<h3>Grid Cells</h3>
<p>
<dfn id="grid-cell">Grid Cell</dfn>s are the logical space used to lay out one or more <i>Grid items</i>. <i>Grid cells</i> may be defined explicitly using the 'grid-template' property, or implicitly by referencing a region of the Grid using the properties 'grid-row' and 'grid-column' on a <i>Grid item</i>.
</p>
<p>
Whether a <i>Grid cell</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 cell</i>. <i>Grid cells</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: "ad"
"bd"
"cd";
grid-columns: 150px 1fr;
grid-rows: 50px 1fr 50px
}
#item2 { grid-cell: "b" }
#item3 { grid-cell: "b" }
/* Align items 2 and 3 at different points in the Grid Cell "b". */
/* By default, Grid Items are stretched to fit their Grid Cell */
/* and these items would layer one over the other. */
#item2 { grid-row-align: start }
#item3 { grid-column-align: end; grid-row-align: end }</style></pre>
<!--End Section: Grid Cells-->
</section>
<!--End Section: Core Concepts of the Grid-->
</section>
<section id="grid-declaration" class="section">
<h2>Grid Declaration</h2>
<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... | <span class="normref"><strong><dfn id="grid">grid</dfn> | <dfn id="inline-grid">inline-grid</dfn></strong></span> |
</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>
<!--End Section: Grid Declaration-->
</section>
<section id="grid-items" class="section">
<h2>Grid Items</h2>
<p>
The <i>Grid element</i> performs layout on <i>Grid items</i>. <dfn id="grid-item">Grid Item</dfn>s are considered block-level children, replaced, inline-block children, and atomic, inline-level children of the <i>Grid element</i>.
</p>
<p>
Contiguous runs of non-replaced, inline content are wrapped in an anonymous, block-level box, which is then treated as a <i>Grid item</i> for the purposes of Grid layout.
Out-of-flow elements (except floats, which are out-of-flow, but are irrelevant to Grid layout since <i>Grid items</i> can't float) leave behind a "placeholder" in their original source location which is treated like a non-replaced, inline element for the purpose of this wrapping.
Any indirect descendants of the <i>Grid element</i>, including block elements that are contained in inline elements, are not <i>Grid items</i>.
</p>
<p>
The following example produces two <a href="#grid-item">Grid Items</a>: the first <i>Grid item</i> is the anonymous block-level box
wrapping the <code>A</code> and the subsequent <code><span></code>; the second <i>Grid item</i> is created by the block-level box of the <code>C <div></code>.
</p>
<pre class="example"><div style="display:grid;">A<span>B</span><div>C</div></div></pre>
<!--End Section: Grid Items-->
</section>
<section class="section" id="defining-grid-rows-columns-and-lines">
<h2>Defining Grid Rows, Columns and Lines</h2>
<section 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-columns: 150px 1fr;
grid-rows: 50px 1fr 50px
}
</style></pre>
<!--End Section: Grid Rows, Columns and Implicit Grid Lines-->
</section>
<section 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-rows' or 'grid-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-columns: "first" "nav" 150px "main" 1fr "last";
grid-rows: "first" "header" 50px "main" 1fr "footer" 50px "last";
}
</style></pre>
<!--End Section: Named Grid Lines-->
</section>
<section class="section" id="grid-starting-and-ending-lines">
<h3>Starting and Ending Grid Lines</h3>
<p>
In addition to any explicitly named <i>Grid lines</i> defined by the author, a <i>Grid element</i> also has four implicitly defined <i>Grid lines</i>: a start and end line for both columns and rows. The <dfn id="start-line">start</dfn> line is always positioned on the starting edge of the <i>Grid element</i>’s content box. The <dfn id="end-line">end</dfn> line is positioned at the ending edge of the <i>Grid element</i>’s content box, or at the same location as the last explicitly or implicitly defined <i>Grid line</i> when it extends past the content box of the <i>Grid element</i>.
</p>
<p>
In the following example, the ‘<a href="#end-line"><code
class=css>end</code></a>’ column <i>Grid line</i> is positioned on the ending edge of the <i>Grid element</i>’s content box. The ‘<a href="#end-line"><code
class=css>end</code></a>’ row <i>Grid line</i> is positioned past the ending edge in overflow at the same location as the <i>Grid line</i> named "last."
</p>
<pre class="example"><style type="text/css">
#grid {
display: grid;
width: auto;
height: 500px;
grid-columns: 50px 1fr;
grid-rows: "first" 250px 250px 250px "last";
}
#item {
/* cover explicitly defined columns and rows */
grid-column: 1 3;
grid-row: "first" "last";
/* equivalent (assuming no implicitly created tracks) */
grid-column: start end;
grid-row: start end;
}
</style></pre>
<!--End Section: Starting and Ending Grid Lines-->
</section>
<section 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 syntax 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 gutter. Note that when repeat syntax 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-columns: 10px "content" 250px 10px 250px 10px 250px 10px 250px 10px;
grid-rows: 1fr;
}
/* Equivalent definition. */
#grid {
display: grid;
grid-columns: 10px ("content" 250px 10px)[4];
grid-rows: 1fr;
}
</style></pre>
<p class="issue">
Consider not allowing named lines in the repeat syntax.
</p>
<!--End Section: Repeating Columns and Rows-->
</section>
<section class="section" id="grid-columns-and-rows-properties">
<h3>Grid-columns and Grid-rows Properties</h3>
<p>
The following grammar expresses the allowable values for the 'grid-rows' and 'grid-columns' properties.
</p>
<code><pre><track-list> => [ [ <string> ]* <track-group> [ <string> ]* ]+ | 'none'
<track-group> => [ '(' [ [ <string> ]* <track-minmax> [ <string> ]* ]+ ')' [ '[' <positive-integer> ']' ]?
| <track-minmax>
<track-minmax> => 'minmax(' <track-breadth> ',' <track-breadth> ')' | 'auto' | <track-breadth> | 'fit-content'
<track-breadth> => <length> | <percentage> | <fraction> | 'min-content' | 'max-content'</pre></code>
<p>Whitespace must not occur between the closing parenthesis and the opening square bracket of the repeat count. Whitespace must occur between any consecutive <code><track-group></code> and <code><track-minmax></code>. In all other areas, whitespace may optionally occur.</p>
<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="fit-content">fit-content</dfn> is equivalent to 'minmax(min-content, max-content)'.</li>
<li><dfn id="auto">auto</dfn> is equivalent to 'fit-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>
<br>
<table id="grid-columns-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-columns">grid-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-rows-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-rows">grid-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 ''start'' 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-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-rows: 1fr minmax(min-content, 1fr);
grid-rows: 10px (1fr auto minmax(30%, 1fr))[2];
grid-rows: (10px);
grid-rows: calc(4em - 5px)</pre>
<!--End Section: Grid-columns and Grid-rows Properties-->
</section>
<section 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-rows' and 'grid-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'-->
</section>
<section id="computed-values-grid-rows-and-columns" class="section">
<h4>Computed Values for Grid-rows and Grid-columns</h4>
<p>
The computed size of all <i>Grid tracks</i> as returned for the 'grid-rows' and 'grid-columns' properties are normalized to used pixel values.
All <i>Grid tracks</i> are included in the computed value reported for 'grid-rows' and 'grid-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-rows' or 'grid-columns' property.
The computed value includes any used values for 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-columns: "a" auto "b" minmax(min-content, 1fr) "b" "c" "d" ("e" 40px)[2] (auto)[5];
}
</style>
<div id="grid">
<div style="grid-column:1; width:50px"></div>
<div style="grid-column:9; width:50px"></div>
</div>
<script type="text/javascript">
// Returns '"a" 50px "b" 320px "c" "d" ("e" 40px)[2] (0px)[4] 50px'.
var gridElement = document.getElementById("grid");
window.getComputedStyle(gridElement, null).getPropertyValue("grid-columns");
</script></pre>
<!--End Section: Fraction Values: 'fr'-->
</section>
<!--End Section: Defining Grid Rows and Columns-->
</section>
<section id="grid-item-placement" class="section">
<h2>Placing Grid Items</h2>
<p>The properties 'grid-row' and 'grid-column' are used to place <i>Grid items</i> in the Grid.</p>
<table id="grid-column-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-column">grid-column</dfn></td>
</tr>
<tr>
<td>Value:</td>
<td>[ [ <integer> | <string> | <dfn id="start-column-position">start</dfn> ] [ <integer> | <string> | <dfn id="end-column-position">end</dfn> ]? ] | <dfn id="auto-column-position">auto</dfn></td>
</tr>
<tr>
<td>Initial:</td>
<td>auto</td>
</tr>
<tr>
<td>Applies to:</td>
<td>Grid Item 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>see text</td>
</tr>
</tbody>
</table>
<table id="grid-row-property" class="propdef">
<tbody>
<tr>
<td>Name:</td>
<td><dfn id="grid-row">grid-row</dfn></td>
</tr>
<tr>
<td>Value:</td>
<td>[ [ <integer> | <string> | <dfn id="start-row-position">start</dfn> ] [ <integer> | <string> | <dfn id="end-row-position">end</dfn> ]? ] | <dfn id="auto-row-position">auto</dfn></td>
</tr>
<tr>
<td>Initial:</td>
<td>auto</td>
</tr>
<tr>
<td>Applies to:</td>
<td>Grid Item 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>see text</td>
</tr>
</tbody>
</table>
<p>
'grid-row' and 'grid-column' properties that refer to an undefined <i>Grid line</i> will compute to their initial values.
</p>
<section id="anonymous-grid-cells" class="section">
<h3>Anonymous Grid Cells</h3>
<p>
Each <i>Grid item</i> is contained by a <i>Grid cell</i>, i.e. the <i>Grid cell</i> serves as the containing block for the <i>Grid item</i>. The dimensions of an anonymous <i>Grid cell</i> are determined by naming the starting and ending <i>Grid lines</i> using the 'grid-row' and 'grid-column' properties on the <i>Grid item</i> which the <i>Grid cell</i> surrounds. The starting and ending lines may be referred to by a string name, if one was defined by the author, the <a href="#start-column-position">start</a> and <a href="#end-column-position">end</a> line keywords, or the <i>Grid line</i>’s number.
</p>
<p>
The following example positions the first <i>Grid item</i> to cover all rows and columns of the <i>Grid element</i> using the <a href="#start-column-position">start</a> and <a href="#end-column-position">end</a> keywords. The second <i>Grid item</i> is positioned to cover the first row. Note that when only the starting <i>Grid line</i> of the 'grid-row' or 'grid-column' properties are specified for the <i>Grid cell</i>, that the <i>Grid cell</i> is assumed to extend to the subsequent <i>Grid line</i>.
</p>
<pre class="example"><style type="text/css">
/* covers the <i>Grid element</i>’s content box */
#item1 {
grid-row: start end;
grid-column: start end;
}
/* covers the first row */
#item2 {
grid-row: start; /* extends to row Grid Line 2 */
grid-column: start end;
}
</style></pre>
<p>
The next example defines rows for header and footer <i>Grid items</i> sized to content, as well as a main region that receives all remaining space. A single column which receives all horizontal space in the Grid's content box is also defined.
</p>
<pre class="example"><style type="text/css">
#grid {
display: grid;
grid-rows: "header" auto "main" 1fr "footer" auto;
grid-columns: 1fr;
}
#header { grid-row: "header"; grid-column: start }
#main { grid-row: "main"; grid-column: start }
#footer { grid-row: "footer"; grid-column: start }
/* Equivalent to the above using grid line numbers instead of names. */
#header { grid-row: 1; grid-column: 1 }
#main { grid-row: 2; grid-column: 1 }
#footer { grid-row: 3; grid-column: 1 }
</style></pre>
<!--End Section: Anonymous Grid Cells-->
</section>
<section id="defining-grid-cells-with-a-template" class="section">
<h3>Defining Grid Cells with a Template</h3>
<p>
<i>Grid cells</i> can also be defined explicitly using one-letter names 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 cells</i> which can be used to position and size the child elements of the Grid.
</p>
<p>
In the following example, a 'grid-template' property is used to create a page layout where cells are defined for header content <code>h</code>, navigational content <code>n</code>, footer content <code>f</code>, and main content <code>m</code>. In English, a row is created for every separate string listed for the 'grid-template' property, and a column is created for the maximum number of letters found in any one string. In orthogonal writing modes the roles of rows and columns are reversed. See Grid Writing Modes for more details.
</p>
<p>
The 'grid-cell' property is specified on <i>Grid items</i> to position the <i>Grid item</i> inside the explicitly named <i>Grid cell</i>.
</p>
<pre class="example"><style type="text/css">
#grid {
display: grid;
grid-template: "hh"
"nm"
"ff"
}
#grid > a {
display:block; /* make anchor tags valid Grid Items */
grid-cell: "n";
}
</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><string>+ | <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>
<table id="grid-cell-property" class="propdef">
<tbody>
<tr>