-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.src.html
More file actions
executable file
·2577 lines (2079 loc) · 98.1 KB
/
Overview.src.html
File metadata and controls
executable file
·2577 lines (2079 loc) · 98.1 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
992E
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
7292
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="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<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:
<!-- <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:
<dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a>
<dt>Editor's draft:
<dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
<dt>Previous version
<dd><a href="http://www.w3.org/TR/2011/WD-css3-grid-layout-20110407/">http://www.w3.org/TR/2011/WD-css3-grid-layout-20110407/</a>
<dt>Issues List:
<dd><a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=Grid+Layout&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">In Bugzilla</a>
<dt>Discussion:
<dd><a href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a> with subject line “<kbd>[[SHORTNAME]] <var>… message topic …</var></kbd>”
<dt>Editors:
<dd class="hcard"><a href="http://www.xanthir.com/contact" class="fn url">Tab Atkins Jr.</a>, <span class="org">Google Inc.</span>
<dd class="hcard"><a href="http://fantasai.inkedblade.net/contact" class="fn url">Elika J. Etemad</a>, <span class="org">Mozilla</span>
<dd class="hcard"><a href="mailto:ratan@microsoft.com">Rossen Atanassov</a>, <span class="org">Microsoft Corporation</span>
<dt>Authors and former editors:
<dd><a href="mailto:alexmog@microsoft.com">Alex Mogilevsky</a>, Microsoft Corporation
<dd><a href="mailto:pcupp@microsoft.com">Phil Cupp</a>, Microsoft Corporation
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>
This CSS module defines a two-dimensional grid-based layout system,
optimized for user interface design.
In the grid layout model,
the children of a grid container can be positioned into arbitrary slots in a flexible or fixed predefined layout grid.
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>The following features are at risk: …
<h2 class="no-num no-toc" id="contents">
Table of contents</h2>
<!--toc-->
<h2 id='intro'>
Introduction and Overview</h2>
<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>
Like tables,
grid layout enables an author to align elements into columns and rows,
but unlike tables,
grid layout doesn't have content structure,
and thus enables a wide variety of layouts not possible with tables.
For example, the children of a grid container can position themselves
such that they overlap and layer similar to positioned elements.
<p>
In addition, the absence of content structure in grid layout 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 container 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 class="issue">
A common use of design grids is to allow content to flow normally, but "snap" components to grid lines based on their normal flow position. Consider adding a grid placement algorithm based on such relative positioning. Note that this is a non-trivial issue as it impacts the static flow of content. In addition, the grid's algorithm currently depends on knowing the position of every grid item in advance to determine the size of its tracks; when snapping to grid lines, however, the line to which the grid item will snap is influenced by both the item's size and the size of tracks the item covers.
<h3 id='background'>
Background and Motivation</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.
</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>
The capabilities of grid layout address these problems.
It 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 into <i>grid areas</i> defined by these columns and rows.
Figure 1 illustrates a basic layout which can be achieved with grid layout.
<h3 id='adapting-to-available-space'>
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 class="caption">
Five grid items arranged according to content size and available space.
</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 class="caption">
Growth in the grid due to an increase in available space.
</div>
<p>
Grid layout can be used to intelligently reflow elements within a webpage.
Figure 2 represents a game with five major areas in the layout:
the game title, stats area, game board, score area, and control area.
The author's intent is to divide the space for the game such that:
<ul>
<li>
The stats area always appears immediately under the game title.
<li>
The game board appears to the right of the stats and title.
<li>
The top of the game title and the game board should always align.
<li>
The bottom of the game board and the stats area align when the game has reached its minimum height,
but otherwise the game board will stretch to take advantage of all the screen real-estate available to it.
<li>
The score area should align into the column created by the game and stats area,
while the controls are centered under the board.
</ul>
<p>
As an alternative to using script to control the absolute position, width, and height of all elements,
the author can use grid layout,
as shown in Figure 3.
The following example shows how an author might achieve all the sizing, placement, and alignment rules declaratively.
<p>
Note that there are multiple ways to specify the structure of the grid
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 on the <i>grid container</i>,
and the 'grid-row-position', 'grid-column-position', 'grid-row-span' and 'grid-column-span' properties on each <i>grid item</i>.
<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-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>
<h3 id='source-independence'>
Source Independence</h3>
<div class="sidefigure">
<p>
<img alt="Image: An arrangement suitable for portrait orientation." src="images/game-portrait.png" />
<p class="caption">An arrangement suitable for ''portrait'' orientation.
</div>
<div class="sidefigure">
<p>
<img alt="Image: An arrangement suitable for landscape orientation." src="images/game-landscape.png" />
<p class="caption">An arrangement suitable for ''landscape'' orientation.
</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 grid layout with media queries,
the author is able to use the same semantic markup,
but rearrange the layout of elements independent of their source order,
to achieve the desired layout in both orientations.
<p>
The following example leverages grid layout’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 grid’s definition changes.
<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>
<h3 id='grid-layering-of-elements'>
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 class="caption">A control composed of layered HTML elements.
</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>
Prior to the introduction of grid layout,
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 grid layout,
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 container</i> is updated.
<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>
<h2 id='grid-concepts'>
Grid Layout Concepts and Terminology</h2>
<p>
In <dfn>grid layout</dfn>,
the content of a <i>grid container</i> is laid out
by positioning and aligning it into a <i>grid</i>.
The <dfn>grid</dfn> is an intersecting set of horizontal and vertical <i>grid lines</i>
that divides the <i>grid container</i>’s space into <i>grid areas</i>,
into which <i>grid items</i> (representing the <i>grid container</i>’s content) can be placed.
There are two sets of <i>grid lines</i>:
one set defining <dfn title="grid column | column">columns</dfn>
that run along the <a href="http://www.w3.org/TR/css3-writing-modes/#block-axis">block axis</a>,
and an orthogonal set defining <dfn title="grid row | row">rows</dfn>
along the <a href="http://www.w3.org/TR/css3-writing-modes/#inline-axis">inline axis</a>.
[[!CSS3-WRITING-MODES]]
<!--
<div class="figure">
<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 container</i> and its tracks, lines, areas and items.
</div>
-->
<div class="figure">
<img class="figure" alt="Image: Grid Lines." src="images/grid-lines.png" />
<p class="caption">Grid lines: Three in the block axis and four in the inline axis.
</div>
<h3 id="grid-track-concept">
Grid Tracks</h3>
<p>
<dfn>Grid track</dfn> is a generic term for a <i>grid column</i> or <i>grid row</i>—in
other words, it is the space between two adjacent <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 its bounding <i>grid lines</i> are.
<div class="example">
<p>
In the following example there are two columns and three rows.
The first column is fixed at 150px.
The second column uses fractional sizing, which is a function of the unassigned space in the Grid,
and thus will vary as the width of the <i>grid container</i> changes.
If the used width of the <i>grid container</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 overflow the <i>grid container</i>.
<pre>
<style type="text/css">
#grid {
display: grid;
grid-definition-columns: 150px 1fr; /* two columns */
grid-definition-rows: 50px 1fr 50px /* three rows */
}
</style></pre>
</div>
<h3 id="grid-line-concept">
Grid Lines</h3>
<p>
<dfn id='grid-line' title='grid line'>Grid lines</dfn> are the horizontal and vertical dividing lines of the <i>grid</i>.
They can be referred to by numerical index,
or by an author-specified name.
A <i>grid item</i> references the <i>grid lines</i> to determine its position within the <i>grid</i>
using the <a href="#placement">grid-placement properties</a>.
<div class="example">
<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>.
<pre>
<style type="text/css">
#grid {
display: grid;
grid-definition-columns: 150px 1fr;
grid-definition-rows: 50px 1fr 50px
}
#item1 { grid-column: 2;
grid-start: 1; grid-end: 1; }
</style></pre>
<pre>
<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>
</div>
<h3 id="grid-area-concept">
Grid Areas</h3>
<p>
A <dfn>grid area</dfn> is the logical space used to lay out one or more <i>grid items</i>.
It is bound by four <i>grid lines</i>, one on each side of the <i>grid area</i>,
and participates in the sizing of the <i>grid tracks</i> it intersects.
A <i>grid area</i> can be named explicitly using the 'grid-template' property of the <i>grid container</i>,
or referenced implicitly by its bounding <i>grid lines</i>.
A <i>grid item</i> is assigned to a <i>grid area</i>
using the <a href="#placement">grid-placement properties</a>.
<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>
<p>
A <i>grid item</i>’s <i>grid area</i> forms the containing block into which it is laid out.
Percentage lengths specified on a <i>grid item</i> resolve against this containing block.
Percentages specified for 'margin-top', 'padding-top', 'margin-bottom', and 'padding-bottom' on a <i>grid item</i>
resolve against the height of its containing block,
rather than the width (as for blocks).
<p>
<i>Grid items</i> placed into the same <i>grid area</i> do not directly affect each other's layout.
Indirectly, a <i>grid item</i> can affect the position of a <i>grid line</i> in a column or row that uses a contents-based relative size,
which in turn can affect the position or size of another <i>grid item</i>.
<h2 id="grid-model">
Grid Layout Box Model and Terminology</h2>
<h3 id='grid-containers'>
Grid Containers: the ''grid'' and ''inline-grid'' 'display' values</h3>
<table class='propdef'>
<tr>
<th>Name:
<td>display
<tr>
<th><a href="#values">New values</a>:
<td>grid | inline-grid
</table>
<dl>
<dt><dfn>grid</dfn>
<dd>
This value causes an element to generate a block-level <i>grid container</i> box.
<dt><dfn>inline-grid</dfn>
<dd>
This value causes an element to generate an inline-level <i>grid container</i> box.
</dl>
<p>
The baseline of an inline <i>Grid element</i> is the bottom edge of the margin box.
<h3>Subgrids: the ''subgrid'' 'display' value</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>
</div>
<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">
<p>
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>Non-children Grid 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>Absolutely Positioned Grid Children</h3>
<h3>Collapsed Grid Items</h3>
<p class='issue'>
Do something with ''visibility:collapse''?
<h2>Defining the Grid</h2>
<p class='issue'>
Fill in text.
<h3 id='track-sizing'>
Track Sizing: the 'grid-definition-rows' and 'grid-definition-columns' properties</h3>
<table class="propdef">
<tr>
<td>Name:
<td><dfn>grid-definition-columns</dfn>, <dfn>grid-definition-rows</dfn>
<tr>
<td>Value:
<td>none | <var><track-list></var>
<tr>
<td>Initial:
<td>none
<tr>
<td>Applies to:
<td><i>grid containers</i>
<tr>
<td>Inherited:
<td>no
<tr>
<td>Percentages:
<td>n/a
<tr>
<td>Media:
<td>visual
<tr>
<td>Computed value:
<td>As specified, except for ''auto'' (see prose)
</table>
<p>
These properties specify,
as a comma-separated list,
the sizing function of each <i>grid track</i> in the <i>grid container</i>’s <i>grid</i>.
The size can be specified as a length,
a percentage of the <i>grid container</i>’s size,
a measurement of the contents occupying the column or row,
or a proportion of the unassigned space in the grid.
It can also be specified as a range using the ''minmax()'' notation,
which can combine any of the previously mentioned mechanisms to define a min and max size for the column or row.
<p>
The following grammar expresses the allowable values for the 'grid-definition-rows' and 'grid-definition-columns' properties.
<pre>
<dfn><track-list></dfn> = [ <var><string></var>* <var><track-group></var> ]+ <var><string></var>*
<dfn><track-group></dfn> =
<var><track-size></var> |
repeat( <var><positive-integer></var> , [ <var><string></var>* <var><track-size></var> ]+ <var><string></var>* )
<dfn><track-size></dfn> = minmax( <var><track-breadth></var> , <var><track-breadth></var> ) | auto | <var><track-breadth></var>
<dfn><track-breadth></dfn> = <var><length></var> | <var><percentage></var> | <var><fraction></var> | min-content | max-content</pre>
<p>Where:
<dl>
<dt><var><length></var>
<dd>
As defined by CSS3 Values. [[!CSS3VAL]]
<dt><var><percentage></var>
<dd>
As defined by CSS3 Values. [[!CSS3VAL]]
<var><percentage></var> values are relative to the measure (logical width) of the <i>grid container</i> in <i>grid column tracks</i>,
and the extent (logical height) of the <i>grid container</i> in <i>grid row tracks</i>.
If the measure or extent of the <i>grid container</i> is an <a href="http://www.w3.org/TR/css3-sizing/#indefinite-size">indefinite size</a>,
<var><percentage></var> values relative to that size are treated as ''auto''.
<dt><dfn id="fraction"><var><fraction></var></dfn>
<dd>
A non-negative dimension with the unit "fr".
Each <var><fraction></var> value takes a share of the remaining space proportional to its value.
See <i>fraction values</i> for more details.
<dt><dfn id="max-content">max-content</dfn>
<dd>
Represents the largest <a href="http://www.w3.org/TR/css3-sizing/#max-size-contribution">max size contribution</a>
of the <i>grid items</i> occupying the <i>grid track</i>.
<dt><dfn id="min-content">min-content</dfn>
<dd>
Represents the largest <a href="http://www.w3.org/TR/css3-sizing/#min-size-contribution">min size contribution</a>
of the <i>grid items</i> occupying the <i>grid track</i>.
<dt><dfn id="minmax">minmax(min, max)</dfn>
<dd>
Defines a size range
greater than or equal to <var>min</var>
and less than or equal to <var>max</var>.
If <var>max</var> < <var>min</var>,
then <var>max</var> is ignored and ''minmax(min,max)'' is treated as <var>min</var>.
<dt><dfn id="auto">auto</dfn>
<dd>
Computes to ''minmax(min-content, max-content)''.
</dl>
<p class="issue">
Handling of percentages inside indefinite-sized grid containers is more similar to blocks/etc,
rather than tables.
(In tables, they imply a table size through black magic.)
Is that all right?
<div class='example'>
<p>
Given the following 'grid-definition-columns' declaration:
<pre>grid-definition-columns: 100px 1fr max-content minmax(min-content, 1fr);</pre>
<p>
Five grid lines are created:
<ol>
<li>
At the start edge of the <i>grid container</i>.
<li>
100px from the start edge of the <i>grid container</i>.
<li>
A distance from the previous line equal to half the <i>free space</i>
(the width of the <i>grid container</i>, minus the width of the non-flexible <i>grid tracks</i>).
<li>
A distance from the previous line equal to the maximum size of any <i>grid items</i>
belonging to the column between these two lines.
<li>
A distance from the previous line at least as large as the largest minimum size of any <i>grid items</i>
belonging to the column between these two lines,
but no larger than the other half of the <i>free space</i>.
</ol>
<p>
If the non-flexible sizes
(''100px'', ''max-content'', and ''min-content'')
sum to larger than the <i>grid container</i>’s width,
the final <i>grid line</i> will be a distance equal to their sum away from the start edge of the <i>grid container</i>
(the ''1fr'' sizes both resolve to ''0'').
If the sum is less than the <i>grid container</i>’s width,
the final <i>grid line</i> will be exactly at the end edge of the <i>grid container</i>.
This is true in general whenever there's at least one <var><fraction></var> value among the <i>grid track</i> sizes.
</div>
<div class='example'>
<p>
Additional examples of valid <i>grid track</i> definitions:
<pre>
/* 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>
</div>
<h4>
Named Grid Lines</h4>
<div class="sidefigure">
<img class="figure" alt="Image: Named Grid Lines." src="images/grid-named-lines.png" />
<p class="caption">Named Grid Lines.
</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.
<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.
<h4 id='repeat-notation'>
Repeating Rows and Columns: the ''repeat()'' notation</h4>
<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>
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.
<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>
<h4 id='fr-unit'>
Flexible Lengths: the ''fr'' unit</h4>
<p>
<dfn id="fraction-values">Fraction values</dfn> are new units applicable to the 'grid-definition-rows' and 'grid-definition-columns' properties:
<dl>
<dt>fr
<dd>Fraction of available space.
</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>
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>
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.
<h4>
Resolved Values</h4>
<p>
The resolved 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 resolved 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 resolved 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.