-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
4272 lines (3370 loc) · 162 KB
/
Overview.html
File metadata and controls
4272 lines (3370 loc) · 162 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://dublincore.org/documents/2008/08/04/dc-html/ ">
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Grid Layout</title>
<link href="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS Grid Layout" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2013-04-25 name=dcterms.date>
<meta content="Tab Atkins Jr." name=dcterms.creator>
<meta content="Elika J. Etemad" name=dcterms.creator>
<meta content="Rossen Atanassov" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://www.w3.org/TR/2013/WD-css3-grid-layout-20130425/"
name=dcterms.identifier>
<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-WD.css" rel=stylesheet
type="text/css">
<style type="text/css">
.example {
clear:both
}
th {
text-align:left
}
.pseudo-code {
font-family:monospace
}
.pseudo-code > ol {
list-style-type:decimal
}
.pseudo-code > ol > li > ol {
list-style-type:lower-latin
}
.pseudo-code > ol > li > ol > li > ol {
list-style-type:lower-roman
}
.pseudo-code ul {
list-style-type:disc
}
dd > p:nth-child(1) {
margin-top:0
}
</style>
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1 class=title id=title>CSS Grid Layout</h1>
<h2 class="no-num no-toc" id=longstatus-date>W3C Working Draft, 25 April
2013</h2>
<dl>
<dt>This version:
<dd><a
href="http://www.w3.org/TR/2013/WD-css3-grid-layout-20130425/">http://www.w3.org/TR/2013/WD-css3-grid-layout-20130425/</a>
<!-- <dd><a href="http://dev.w3.org/csswg/css3-grid-layout/">http://dev.w3.org/csswg/css3-grid-layout/</a> -->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-grid-layout/">http://www.w3.org/TR/css3-grid-layout/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-grid-layout/">http://dev.w3.org/csswg/css3-grid-layout/</a>
<dt>Previous version
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-grid-layout-20121106/">http://www.w3.org/TR/2012/WD-css3-grid-layout-20121106/</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>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss3-grid-layout%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css3-grid-layout] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class=hcard><a class="fn url"
href="http://www.xanthir.com/contact">Tab Atkins Jr.</a>, <span
class=org>Google Inc.</span>
<dd class=hcard><a class="fn url"
href="http://fantasai.inkedblade.net/contact">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>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=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>
<!--begin-status-->
<p><em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href="http://www.w3.org/TR/">W3C technical reports
index at http://www.w3.org/TR/.</a></em>
<p>Publication as a Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a href="mailto:www-style@w3.org">www-style@w3.org</a> (see
<a href="http://www.w3.org/Mail/Request">instructions</a>) is preferred
for discussion of this specification. When sending e-mail, please put the
text “css3-grid-layout” in the subject, preferably like this:
“[<!---->css3-grid-layout<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<p>The following features are at risk: …
<h2 class="no-num no-toc" id=contents> Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction and
Overview</a>
<ul class=toc>
<li><a href="#background"><span class=secno>1.1. </span> Background and
Motivation</a>
<li><a href="#adapting-to-available-space"><span class=secno>1.2.
</span> Adapting Layouts to Available Space</a>
<li><a href="#source-independence"><span class=secno>1.3. </span> Source
Independence</a>
<li><a href="#grid-layering"><span class=secno>1.4. </span> Grid
Layering of Elements</a>
</ul>
<li><a href="#grid-concepts"><span class=secno>2. </span> Grid Layout
Concepts and Terminology</a>
<ul class=toc>
<li><a href="#grid-track-concept"><span class=secno>2.1. </span> Grid
Tracks</a>
<li><a href="#grid-line-concept"><span class=secno>2.2. </span> Grid
Lines</a>
<li><a href="#grid-area-concept"><span class=secno>2.3. </span> Grid
Areas</a>
</ul>
<li><a href="#grid-model"><span class=secno>3. </span> Grid Layout Box
Model</a>
<ul class=toc>
<li><a href="#grid-containers"><span class=secno>3.1. </span> Grid
Containers: the ‘<code class=css>grid</code>’ and ‘<code
class=css>inline-grid</code>’ ‘<code
class=property>display</code>’ values</a>
<li><a href="#subgrids-the-subgrid-display-value"><span class=secno>3.2.
</span>Subgrids: the ‘<code class=css>subgrid</code>’ ‘<code
class=property>display</code>’ value</a>
</ul>
<li><a href="#grid-items"><span class=secno>4. </span> Grid Items</a>
<ul class=toc>
<li><a href="#position-grid"><span class=secno>4.1. </span> Non-children
Grid Items</a>
<li><a href="#abspos-items"><span class=secno>4.2. </span>
Absolutely-positioned Grid Children</a>
<li><a href="#visibility-collapse"><span class=secno>4.3. </span>
Collapsed Grid Items: the ‘<code class=property>visibility</code>’
property</a>
<li><a href="#order-property"><span class=secno>4.4. </span> Reordered
Grid Items: the ‘<code class=property>order</code>’ property</a>
</ul>
<li><a href="#grid-definition"><span class=secno>5. </span> Defining the
Grid</a>
<ul class=toc>
<li><a href="#track-sizing"><span class=secno>5.1. </span> Track Sizing:
the ‘<code class=property>grid-definition-rows</code>’ and ‘<code
class=property>grid-definition-columns</code>’ properties</a>
<ul class=toc>
<li><a href="#named-lines"><span class=secno>5.1.1. </span> Named Grid
Lines</a>
<li><a href="#repeat-notation"><span class=secno>5.1.2. </span>
Repeating Rows and Columns: the ‘<code class=css>repeat()</code>’
notation</a>
<li><a href="#fr-unit"><span class=secno>5.1.3. </span> Flexible
Lengths: the ‘<code class=css>fr</code>’ unit</a>
<li><a href="#resolved-track-list"><span class=secno>5.1.4. </span>
Resolved Values</a>
</ul>
<li><a href="#grid-template-property"><span class=secno>5.2. </span>
Named Areas: the ‘<code class=property>grid-template</code>’
property</a>
<li><a href="#auto-tracks"><span class=secno>5.3. </span> Auto-generated
Rows and Columns: the ‘<code class=property>grid-auto-rows</code>’
and ‘<code class=property>grid-auto-columns</code>’ properties</a>
</ul>
<li><a href="#placement"><span class=secno>6. </span> Placing Grid
Items</a>
<ul class=toc>
<li><a href="#line-placement"><span class=secno>6.1. </span> Line-based
Placement: the ‘<code class=property>grid-before</code>’, ‘<code
class=property>grid-start</code>’, ‘<code
class=property>grid-after</code>’, and ‘<code
class=property>grid-end</code>’ properties</a>
<li><a href="#placement-shorthands"><span class=secno>6.2. </span>
Placement Shorthands: the ‘<code
class=property>grid-column</code>’, ‘<code
class=property>grid-row</code>’, and ‘<code
class=property>grid-area</code>’ properties</a>
<li><a href="#grid-auto-flow-property"><span class=secno>6.3. </span>
Automatic Placement: the ‘<code
class=property>grid-auto-flow</code>’ property</a>
<ul class=toc>
<li><a href="#auto-placement-algo"><span class=secno>6.3.1. </span>
Automatic Grid Item Placement Algorithm</a>
</ul>
</ul>
<li><a href="#alignment"><span class=secno>7. </span> Alignment</a>
<ul class=toc>
<li><a href="#auto-margins"><span class=secno>7.1. </span> Aligning with
‘<code class=css>auto</code>’ margins</a>
<li><a href="#row-align"><span class=secno>7.2. </span> Row-axis
Alignment: the ‘<code class=property>justify-self</code>’ and
‘<code class=property>justify-items</code>’ properties</a>
<li><a href="#column-align"><span class=secno>7.3. </span> Column-axis
Alignment: the ‘<code class=property>align-self</code>’ and
‘<code class=property>align-items</code>’ properties</a>
<li><a href="#z-order"><span class=secno>7.4. </span> Z-axis Ordering:
the ‘<code class=property>z-index</code>’ property</a>
<li><a href="#grid-baselines"><span class=secno>7.5. </span> Grid
Baselines</a>
</ul>
<li><a href="#layout-algorithm"><span class=secno>8. </span> Grid Layout
Algorithm</a>
<ul class=toc>
<li><a href="#algo-terms"><span class=secno>8.1. </span> Definition of
Terms for use in Calculating Grid Track Sizes</a>
<li><a href="#grid-track-sizing-algorithm"><span class=secno>8.2.
</span> Grid Track Sizing Algorithm</a>
<li><a href="#shrink-to-fit"><span class=secno>8.3. </span> Defining the
Shrink-to-fit Behavior of Grid Elements</a>
</ul>
<li><a href="#pagination"><span class=secno>9. </span> Fragmenting Grid
Layout</a>
<li><a href="#conformance"><span class=secno>10. </span> Conformance</a>
<ul class=toc>
<li><a href="#interactions"><span class=secno>10.1. </span> Module
interactions</a>
<li><a href="#values"><span class=secno>10.2. </span> Values</a>
<li><a href="#conventions"><span class=secno>10.3. </span> Document
conventions</a>
<li><a href="#conformance-classes"><span class=secno>10.4. </span>
Conformance classes</a>
<li><a href="#partial"><span class=secno>10.5. </span> Partial
implementations</a>
<li><a href="#experimental"><span class=secno>10.6. </span> Experimental
implementations</a>
<li><a href="#testing"><span class=secno>10.7. </span> Non-experimental
implementations</a>
</ul>
<li class=no-num><a href="#acknowledgements"> Acknowledgements</a>
<li class=no-num><a href="#references"> References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references"> Normative
references</a>
<li class=no-num><a href="#other-references"> Other references</a>
</ul>
<li class=no-num><a href="#index"> Index</a>
<li class=no-num><a href="#property-index"> Property index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span> 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><span class=secno>1.1. </span> Background and Motivation</h3>
<div class=sidefigure> <img
alt="Image: Application layout example requiring horizontal and vertical alignment."
class=figure src="images/basic-form.png">
<p class=caption>Application layout example requiring horizontal and
vertical alignment.
</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 <a href="#grid-area"><i>grid areas</i></a> 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><span class=secno>1.2. </span> Adapting
Layouts to Available Space</h3>
<div class=sidefigure>
<p> <img
alt="Image: Five grid items arranged according to content size and available space."
src="images/game-smaller.png">
<p 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 <a href="#grid-item"><i>grid items</i></a>, each
optimized for different scenarios. This example illustrates one that an
author may use to define the position and space for each <a
href="#grid-item"><i>grid item</i></a> using the ‘<a
href="#grid-definition-rows"><code
class=property>grid-definition-rows</code></a>’ and ‘<a
href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ properties on the <a
href="#grid-container"><i>grid container</i></a>, and the ‘<a
href="#grid-row"><code class=property>grid-row</code></a>’ and ‘<a
href="#grid-column"><code class=property>grid-column</code></a>’
properties on each <a href="#grid-item"><i>grid item</i></a>.
<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-definition-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-definition-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; justify-self: start }
#board { grid-column: 2; grid-row: 1 / span 2; }
#controls { grid-column: 2; grid-row: 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><span class=secno>1.3. </span> 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 ‘<code
class=css>portrait</code>’ 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 ‘<code
class=css>landscape</code>’ 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 <a href="#grid-item"><i>grid
item</i></a>. This allows the author to avoid rewriting rules for <a
href="#grid-item"><i>grid items</i></a> as the 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 a 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><span class=secno>1.4. </span> Grid Layering of
Elements</h3>
<div class=sidefigure>
<p> <img alt="Image: A control composed of layered HTML elements."
src="images/control-layering-and-alignment.png">
<p 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 flex-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 ‘<a href="#grid-definition-columns"><code
class=property>grid-definition-columns</code></a>’ property of the <a
href="#grid-container"><i>grid container</i></a> 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";
}
/* The grid-placement properties accept named lines. Below the
* lines are referred to by name. Beyond any
* semantic advantage, the names also allow the author to avoid
* renumbering the grid-start and grid-before 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-start: "start" }
#track { grid-column: "track-start" / "track-end"; align-self: center }
#upper-label { grid-end: "end"; }
/* Fill parts are drawn above the track so set z-index to 5. */
#lower-fill { grid-column: "track-start" / "fill-split";
align-self: end;
z-index: 5 }
#upper-fill { grid-column: "fill-split" / "track-end";
align-self: start;
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><span class=secno>2. </span> Grid Layout Concepts and
Terminology</h2>
<p> In <dfn id=grid-layout>grid layout</dfn>, the content of a <a
href="#grid-container"><i>grid container</i></a> is laid out by
positioning and aligning it into a <a
href="#display-grid"><i>grid</i></a>. The <dfn id=grid>grid</dfn> is an
intersecting set of horizontal and vertical <a href="#grid-line"><i>grid
lines</i></a> that divides the <a href="#grid-container"><i>grid
container</i></a>’s space into <a href="#grid-area"><i>grid
areas</i></a>, into which <a href="#grid-item"><i>grid items</i></a>
(representing the <a href="#grid-container"><i>grid container</i></a>’s
content) can be placed. There are two sets of <a href="#grid-line"><i>grid
lines</i></a>: one set defining <dfn id=columns
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 id=rows
title="grid row | row">rows</dfn> along the <a
href="http://www.w3.org/TR/css3-writing-modes/#inline-axis">inline
axis</a>. <a href="#CSS3-WRITING-MODES"
rel=biblioentry>[CSS3-WRITING-MODES]<!--{{!CSS3-WRITING-MODES}}--></a>
<!--
<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 alt="Image: Grid Lines." class=figure
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><span class=secno>2.1. </span> Grid Tracks</h3>
<p> <dfn id=grid-track>Grid track</dfn> is a generic term for a <a
href="#columns"><i>grid column</i></a> or <a href="#rows"><i>grid
row</i></a>—in other words, it is the space between two adjacent <a
href="#grid-line"><i>grid lines</i></a>. Each <a
href="#grid-track"><i>grid track</i></a> is assigned a sizing function,
which controls how wide or tall the column or row may grow, and thus how
far apart its bounding <a href="#grid-line"><i>grid lines</i></a> 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 flexible sizing,
which is a function of the unassigned space in the Grid, and thus will
vary as the width of the <a href="#grid-container"><i>grid
container</i></a> changes. If the used width of the <a
href="#grid-container"><i>grid container</i></a> 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 <a href="#grid-container"><i>grid
container</i></a>.
<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><span class=secno>2.2. </span> Grid Lines</h3>
<p> <dfn id=grid-line title="grid line|grid row line|grid column line">Grid
lines</dfn> are the horizontal and vertical dividing lines of the <a
href="#display-grid"><i>grid</i></a>. A <a href="#grid-line"><i>grid
line</i></a> exists on either side of a column or row. They can be
referred to by numerical index, or by an author-specified name. A <a
href="#grid-item"><i>grid item</i></a> references the <a
href="#grid-line"><i>grid lines</i></a> to determine its position within
the <a href="#display-grid"><i>grid</i></a> using the <a
href="#placement">grid-placement properties</a>.
<div class=example>
<p> The following two examples create three column <a
href="#grid-line"><i>grid lines</i></a> and four row <a
href="#grid-line"><i>grid lines</i></a>. The first example demonstrates
how an author would position a <a href="#grid-item"><i>grid item</i></a>
using <a href="#grid-line"><i>grid line</i></a> numbers. The second
example uses explicitly named <a href="#grid-line"><i>grid lines</i></a>.
<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><span class=secno>2.3. </span> Grid Areas</h3>
<p> A <dfn id=grid-area>grid area</dfn> is the logical space used to lay
out one or more <a href="#grid-item"><i>grid items</i></a>. It is bound by
four <a href="#grid-line"><i>grid lines</i></a>, one on each side of the
<a href="#grid-area"><i>grid area</i></a>, and participates in the sizing
of the <a href="#grid-track"><i>grid tracks</i></a> it intersects. A <a
href="#grid-area"><i>grid area</i></a> can be named explicitly using the
‘<a href="#grid-template"><code
class=property>grid-template</code></a>’ property of the <a
href="#grid-container"><i>grid container</i></a>, or referenced implicitly
by its bounding <a href="#grid-line"><i>grid lines</i></a>. A <a
href="#grid-item"><i>grid item</i></a> is assigned to a <a
href="#grid-area"><i>grid area</i></a> 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 <a href="#grid-item"><i>grid item</i></a>’s <a
href="#grid-area"><i>grid area</i></a> forms the containing block into
which it is laid out. Percentage lengths specified on a <a
href="#grid-item"><i>grid item</i></a> resolve against this containing
block. Percentages specified for ‘<code
class=property>margin-top</code>’, ‘<code
class=property>padding-top</code>’, ‘<code
class=property>margin-bottom</code>’, and ‘<code
class=property>padding-bottom</code>’ on a <a href="#grid-item"><i>grid
item</i></a> resolve against the height of its containing block, rather
than the width (as for blocks).
<p> <a href="#grid-item"><i>Grid items</i></a> placed into the same <a
href="#grid-area"><i>grid area</i></a> do not directly affect each other's
layout. Indirectly, a <a href="#grid-item"><i>grid item</i></a> can affect
the position of a <a href="#grid-line"><i>grid line</i></a> in a column or
row that uses a contents-based relative size, which in turn can affect the
position or size of another <a href="#grid-item"><i>grid item</i></a>.
<h2 id=grid-model><span class=secno>3. </span> Grid Layout Box Model</h2>
<h3 id=grid-containers><span class=secno>3.1. </span> Grid Containers: the
‘<a href="#display-grid"><code class=css>grid</code></a>’ and ‘<a
href="#display-inline-grid"><code class=css>inline-grid</code></a>’
‘<code class=property>display</code>’ values</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td>display
<tr>
<th><a href="#values">New Values</a>:
<td>grid | inline-grid
</table>
<dl>
<dt><dfn id=display-grid>‘<code class=css>grid</code>’</dfn>
<dd> This value causes an element to generate a block-level <a
href="#grid-container"><i>grid container</i></a> box.
<dt><dfn id=display-inline-grid>‘<code
class=css>inline-grid</code>’</dfn>
<dd> This value causes an element to generate an inline-level <a
href="#grid-container"><i>grid container</i></a> box.
</dl>
<p> A <dfn id=grid-container>grid container</dfn> establishes a new <dfn
id=grid-formatting-context>grid formatting context</dfn> for its contents.
This is the same as establishing a block formatting context, except that
grid layout is used instead of block layout: floats do not intrude into
the grid container, and the grid container's margins do not collapse with
the margins of its contents. <a href="#grid-container"><i>Grid
containers</i></a> form a containing block for their contents <a
href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">exactly
like block containers do</a>. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> The ‘<code
class=property>overflow</code>’ property applies to <a
href="#grid-container"><i>grid containers</i></a>.
<p> Grid containers are not block containers, and so some properties that
were designed with the assumption of block layout don't apply in the
context of grid layout. In particular:
<ul>
<li> all of the ‘<code class=css>column-*</code>’ properties in the
Multicol module have no effect on a grid container.
<li> ‘<code class=property>float</code>’ and ‘<code
class=property>clear</code>’ have no effect on a <a
href="#grid-item"><i>grid item</i></a>. (However, the ‘<code
class=property>float</code>’ property still affects the computed value
of ‘<code class=property>display</code>’ on children of a grid
container, as this occurs <em title="">before</em> <a
href="#grid-item"><i>grid items</i></a> are determined.)
<li> ‘<code class=property>vertical-align</code>’ has no effect on a
grid item.
<li> the ‘<code class=css>::first-line</code>’ and ‘<code
class=css>::first-letter</code>’ pseudo-elements do not apply to <a
href="#grid-container"><i>grid containers</i></a>.
</ul>
<p> If an element's specified ‘<code class=property>display</code>’ is
‘<a href="#display-inline-grid"><code
class=css>inline-grid</code></a>’ and the element is floated or
absolutely positioned, the computed value of ‘<code
class=property>display</code>’ is <a href="#display-grid">‘<code
class=css>grid</code>’</a>. The table in <a
href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter
9.7</a> is thus amended to contain an additional row, with ‘<a
href="#display-inline-grid"><code class=css>inline-grid</code></a>’ in
the "Specified Value" column and <a href="#display-grid">‘<code
class=css>grid</code>’</a> in the "Computed Value" column.
<h3 id=subgrids-the-subgrid-display-value><span class=secno>3.2.
</span>Subgrids: the ‘<code class=css>subgrid</code>’ ‘<code
class=property>display</code>’ value</h3>
<div class=issue> This is a proposal to address the alignment of sub-items
across grid items, so that, for example, a grid of labels + inputs (with
each pair styled as a unit) can still align the individual elements in a
greater grid. Potential issues:
4EE8
<ul>
<li> If an item is positioned outside the subgrid's declared
rows/columns, does the subgrid expand further into the outer grid, or
just overflow within its declared bounds?
<li> How to declare a subgrid? As a separate display type, as illustrated
here, or by assigning a "subgrid" value to grid-definition-rows/columns
(which would allow aligning to the parent grid in only one dimension)?
<li> Can auto-placement in the subgrid determine/increase the size of the
subgrid?
<li> Should you be able to interleave lines from the parent grid with
subgrid lines?
</ul>
</div>
<p> A <a href="#grid-item"><i>grid item</i></a> can itself be a <a
href="#grid-container"><i>grid container</i></a> by giving it ‘<code
class=css>display: grid</code>’; 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 <a
href="#grid-item"><i>grid items</i></a> to align to each other; in this
case ‘<code class=css>display: subgrid</code>’ can be used. A <a
href="#grid-item"><i>grid item</i></a> with ‘<code class=css>display:
subgrid</code>’ behaves just like one with ‘<code class=css>display:
grid</code>’ except that:
<ul>