-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·4436 lines (3458 loc) · 164 KB
/
Overview.html
File metadata and controls
executable file
·4436 lines (3458 loc) · 164 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
35
A0B3
6
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>
<html lang=en>
<head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Flexible Box Layout Module</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 Flexible Box Layout Module" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2012-12-03 name=dcterms.issued>
<meta content="http://dev.w3.org/csswg/css3-flexbox/" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://www.w3.org/TR/2012/ED-css3-flexbox-20121203/"
name=dcterms.identifier>
<link href="http://dev.w3.org/csswg/default.css" rel=stylesheet
type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet
type="text/css">
<style>
code.one-line { white-space: pre; }
.code-and-figure {
display: table;
margin: 0 auto;
border-spacing: 1em;
}
.code-and-figure > div {
display: table-cell;
vertical-align: middle;
}
:not(code) var { font-style: normal; color: #005A9C; }
i { font-style: normal; }
ol[start="0"] { counter-reset: list -1; }
ol[start="0"],
ol.continue { list-style: none; }
ol[start="0"] > li,
ol.continue > li { position: relative; counter-increment: list; }
ol[start="0"] > li::before,
ol.continue > li::before { content: counter(list) "."; position: absolute; left: -4.5em; width: 4em; text-align: right; }
.compact, .compact li {
margin-top: 0;
margin-bottom: 0;
}
/* Overview catalog example */
#overview-example {
display:table;
margin: 0 auto 1em;
border-spacing: .5em 0;
min-width: 672px;
}
#overview-example > .col {
display: table-column;
background: hsl(60,100%,90%);
}
#overview-example > .desc {
display: table-cell;
vertical-align: top;
width: 300px;
padding: 1em 1em 0;
text-align: left;
border: thick solid hsl(60,80%,50%);
border-radius: 1em 1em 0 0;
border-bottom: none;
}
#overview-example > .desc > img {
margin: 0 auto;
display: block;
}
#overview-example > .desc > h1 {
background: transparent;
}
#overview-example > .buttons {
display: table-row;
}
#overview-example > .buttons > div {
display: table-cell;
border: thick solid hsl(60,80%,50%);
border-radius: 0 0 1em 1em;
border-top: none;
text-align: center;
}
#overview-example button {
background-color: hsl(120,100%,40%);
border: medium inset hsl(120,70%,40%);
border-radius: 1em;
padding: .5em;
font-weight: bold;
color: white;
font-size: 1.6em;
cursor: pointer;
width: 90%;
margin: 1em auto;
}
/* Visibility: Collapse example */
#visibility-collapse-example {
display: table;
width: 100%;
box-shadow: 3px 3px 10px #333;
}
#visibility-collapse-example > article,
#visibility-collapse-example > nav {
display: table-cell;
}
#visibility-collapse-example > article {
width: 100%;
background: white;
}
#visibility-collapse-example ul,
#visibility-collapse-example li {
list-style: none;
margin: 0;
padding: 0;
}
#visibility-collapse-example > nav > ul {
background: #444;
border-radius: 0.5em;
padding: 0.075em;
}
#visibility-collapse-example li {
padding: 0 0.5em;
background: #ddd;
color: black;
border-radius: 0.40em;
border: #444 solid 0.075em;
}
#visibility-collapse-example li li {
background: #444;
color: white;
margin: 0 -0.5em;
border-radius: 0;
}
#visibility-collapse-example li li:first-child {
border-radius: 0.375em 0.375em 0 0;
}
#visibility-collapse-example a {
background: transparent;
color: inherit;
}
#visibility-collapse-example > nav > ul > li:target,
#visibility-collapse-example > nav > ul > li:hover {
background: #888;
color: white;
}
#visibility-collapse-example > nav > ul > li:not(:target):not(:hover) > ul {
height: 0;
overflow: hidden;
}
#auto-bar {
overflow: hidden;
padding: .25em 1em;
background: #ddd;
list-style: none;
margin: 0;
border-radius: .3em;
}
#auto-bar > li {
float: left;
color: black;
margin: 0;
}
#auto-bar > li:first-child:after,
#auto-bar > li:first-child + li:after {
content: " | ";
white-space: pre;
}
#auto-bar > li > a {
display: inline-block;
padding: 0 .25em;
border-radius: .3em;
}
#auto-bar > li > a:not(:hover):not(:focus) {
text-decoration: none;
}
#auto-bar > li > a:hover {
color: #ddd;
background: #444;
}
#auto-bar > #login { float: right; }
.cross-auto-figure > div {
margin: 0 auto;
width: 70px;
background: #888;
padding: 0 .5em;
border-radius: 1em;
border: 1px solid transparent;
}
.cross-auto-figure > div > div {
border-spacing: 0;
display: table;
background: #ddd;
color: black;
text-align: center;
margin: .5em auto;
padding: .5em;
border-radius: .5em;
}
.axis { color: hsl( 0,80%,40%); }
.side { color: hsl(240,80%,50%); }
.size { color: hsl(120,80%,30%); }
</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 id=head-box-flexible>CSS Flexible Box Layout Module</h1>
<h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 3 December 2012</h2>
<dl>
<dt>This version:
<!--<dd><a href="http://www.w3.org/TR/2012/ED-css3-flexbox-20121203/">http://www.w3.org/TR/2012/CR-css3-flexbox-20121203/</a>-->
<dd><a
href="http://dev.w3.org/csswg/css3-flexbox/">http://dev.w3.org/csswg/css3-flexbox/</a>
<dt>Latest version:
<!--<dd><a href="http://www.w3.org/TR/css3-flexbox/">http://www.w3.org/TR/css3-flexbox/</a>-->
<dd><a
href="http://www.w3.org/TR/css3-flexbox/">http://www.w3.org/TR/css3-flexbox/</a>
<dt>Editor's Draft:
<dd><a
href="http://dev.w3.org/csswg/css3-flexbox/">http://dev.w3.org/csswg/css3-flexbox/</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2012/CR-css3-flexbox-20120921/">http://www.w3.org/TR/2012/CR-css3-flexbox-20120921/</a>
<dt>Issues List:
<dd><a
href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=Flexbox&resolution=---">Bugzilla
Bugs for Flexbox</a>
<dt>Discussion:
<dd><a
href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a>
with subject line "<code>[css3-flexbox] …message topic…</code>"
<dt>Editors:
<dd><a href="http://www.xanthir.com/contact">Tab Atkins Jr.</a>, Google
Inc.
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>,
Mozilla
<dd>Alex Mogilevsky, Microsoft Corporation, <a
href="mailto:alexmog@microsoft.com">alexmog@microsoft.com</a>
<dt>Authors and former editors:
<dd>L. David Baron, Mozilla Corporation, <a
href="mailto:dbaron@dbaron.org">dbaron@dbaron.org</a>
<dd>Neil Deakin, Mozilla Corporation, <a
href="mailto:enndeakin@gmail.com">enndeakin@gmail.com</a>
<dd>Ian Hickson, formerly of Opera Software, <a
href="mailto:ian@hixie.ch">ian@hixie.ch</a>
<dd>David Hyatt, formerly of Netscape Corporation, <a
href="mailto:hyatt@apple.com">hyatt@apple.com</a>
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2012 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract> Abstract</h2>
<p> The specification describes a CSS box model optimized for user
interface design. In the flex layout model, the children of a flex
container can be laid out in any direction, and can "flex" their sizes,
either growing to fill unused space or shrinking to avoid overflowing the
parent. Both horizontal and vertical alignment of the children can be
easily manipulated. Nesting of these boxes (horizontal inside vertical, or
vertical inside horizontal) can be used to build layouts in two
dimensions.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<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>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-flexbox%5D%20PUT%20SUBJECT%20HERE">
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-flexbox” in the subject, preferably like this:
“[<!---->css3-flexbox<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/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="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p>The CR period will last at least until 20 March 2013. At the time of
publication, no test suite and implementation report have yet been made.
They will be made available from the <a href="/Style/CSS/Test/">CSS test
suites page</a>. See the section <a href="#cr-exit-criteria">“CR exit
criteria”</a> for details.
<p>See the section <a href="#changes">“Changes”</a> for changes made to
this specification since the last Working Draft.
<p> The following features are at-risk:
<ul>
<li>Calculation of the static position of absolutely-positioned flex
items.
</ul>
<h2 class="no-num no-toc" id=table>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction</a>
<ul class=toc>
<li><a href="#overview"><span class=secno>1.1. </span> Overview</a>
<li><a href="#placement"><span class=secno>1.2. </span> Module
interactions</a>
<li><a href="#values"><span class=secno>1.3. </span> Values</a>
</ul>
<li><a href="#box-model"><span class=secno>2. </span> Flex Layout Box
Model and Terminology</a>
<li><a href="#flex-containers"><span class=secno>3. </span> Flex
Containers: the ‘<code class=css>flex</code>’ and ‘<code
class=css>inline-flex</code>’ ‘<code class=property>display</code>’
values</a>
<li><a href="#flex-items"><span class=secno>4. </span> Flex Items</a>
<ul class=toc>
<li><a href="#abspos-items"><span class=secno>4.1. </span>
Absolutely-Positioned Flex Children</a>
<li><a href="#item-margins"><span class=secno>4.2. </span> Flex Item
Margins</a>
<li><a href="#painting"><span class=secno>4.3. </span> Flex Item
Painting</a>
<li><a href="#visibility-collapse"><span class=secno>4.4. </span>
Collapsed Items</a>
<li><a href="#min-size-auto"><span class=secno>4.5. </span> Implied
Minimum Size of Flex Items</a>
</ul>
<li><a href="#ordering-and-orientation"><span class=secno>5. </span>
Ordering and Orientation</a>
<ul class=toc>
<li><a href="#flex-direction-property"><span class=secno>5.1. </span>
Flex Flow Direction: the ‘<code
class=property>flex-direction</code>’ property</a>
<li><a href="#flex-wrap-property"><span class=secno>5.2. </span> Flex
Line Wrapping: the ‘<code class=property>flex-wrap</code>’
property</a>
<li><a href="#flex-flow-property"><span class=secno>5.3. </span> Flex
Direction and Wrap: the ‘<code class=property>flex-flow</code>’
shorthand</a>
<li><a href="#order-property"><span class=secno>5.4. </span> Display
Order: the ‘<code class=property>order</code>’ property</a>
<ul class=toc>
<li><a href="#order-accessibility"><span class=secno>5.4.1. </span>
Reordering and Accessibility</a>
</ul>
</ul>
<li><a href="#flex-lines"><span class=secno>6. </span> Flex Lines</a>
<li><a href="#flexibility"><span class=secno>7. </span> Flexibility</a>
<ul class=toc>
<li><a href="#flex-property"><span class=secno>7.1. </span> The ‘<code
class=property>flex</code>’ Shorthand</a>
<li><a href="#flex-common"><span class=secno>7.2. </span> Common Values
of ‘<code class=property>flex</code>’</a>
<li><a href="#flex-components"><span class=secno>7.3. </span> Components
of Flexibility</a>
<ul class=toc>
<li><a href="#flex-grow-property"><span class=secno>7.3.1. </span> The
‘<code class=property>flex-grow</code>’ property</a>
<li><a href="#flex-shrink-property"><span class=secno>7.3.2. </span>
The ‘<code class=property>flex-shrink</code>’ property</a>
<li><a href="#flex-basis-property"><span class=secno>7.3.3. </span>
The ‘<code class=property>flex-basis</code>’ property</a>
</ul>
</ul>
<li><a href="#alignment"><span class=secno>8. </span> Alignment</a>
<ul class=toc>
<li><a href="#auto-margins"><span class=secno>8.1. </span> Aligning with
‘<code class=css>auto</code>’ margins</a>
<li><a href="#justify-content-property"><span class=secno>8.2. </span>
Axis Alignment: the ‘<code class=property>justify-content</code>’
property</a>
<li><a href="#align-items-property"><span class=secno>8.3. </span>
Cross-axis Alignment: the ‘<code class=property>align-items</code>’
and ‘<code class=property>align-self</code>’ properties</a>
<li><a href="#align-content-property"><span class=secno>8.4. </span>
Packing Flex Lines: the ‘<code class=property>align-content</code>’
property</a>
<li><a href="#flex-baselines"><span class=secno>8.5. </span> Flex
Baselines</a>
</ul>
<li><a href="#layout-algorithm"><span class=secno>9. </span> Flex Layout
Algorithm</a>
<ul class=toc>
<li><a href="#box-manip"><span class=secno>9.1. </span> Initial
Setup</a>
<li><a href="#line-sizing"><span class=secno>9.2. </span> Line Length
Determination</a>
<li><a href="#main-sizing"><span class=secno>9.3. </span> Main Size
Determination</a>
<li><a href="#cross-sizing"><span class=secno>9.4. </span> Cross size
determination</a>
<li><a href="#main-alignment"><span class=secno>9.5. </span> Main-Axis
Alignment</a>
<li><a href="#cross-alignment"><span class=secno>9.6. </span> Cross-Axis
Alignment</a>
<li><a href="#resolve-flexible-lengths"><span class=secno>9.7. </span>
Resolving Flexible Lengths</a>
</ul>
<li><a href="#pagination"><span class=secno>10. </span> Fragmenting Flex
Layout</a>
<ul class=toc>
<li><a href="#pagination-algo"><span class=secno>10.1. </span> Sample
Flex Fragmentation Algorithm</a>
</ul>
<li><a href="#conformance"><span class=secno>11. </span> Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>11.1. </span> Document
conventions</a>
<li><a href="#conformance-classes"><span class=secno>11.2. </span>
Conformance classes</a>
<li><a href="#partial"><span class=secno>11.3. </span> Partial
implementations</a>
<li><a href="#experimental"><span class=secno>11.4. </span> Experimental
implementations</a>
<li><a href="#testing"><span class=secno>11.5. </span> Non-experimental
implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>11.6. </span> CR exit
criteria</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative">Normative references</a>
<li class=no-num><a href="#informative">Other references</a>
</ul>
<li class=no-num><a href="#changes">Changes</a>
<li class=no-num><a href="#property">Property index</a>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span> Introduction</h2>
<p><em>This section is not normative.</em>
size and position of boxes based on their relationships with their sibling
and ancestor boxes:
<ul class=compact>
<li>block layout, designed for laying out documents
<li>inline layout, designed for laying out text
<li>table layout, designed for laying out 2D data in a tabular format
<li>positioned layout, designed for very explicit positioning without much
regard for other elements in the document
</ul>
<p> This module introduces a new layout mode, <dfn id=flex-layout>flex
layout</dfn>, which is designed for laying out more complex applications
and webpages.
<h3 id=overview><span class=secno>1.1. </span> Overview</h3>
<p><em>This section is not normative.</em>
<p> Flex layout is superficially similar to block layout. It lacks many of
the more complex text- or document-centric properties that can be used in
block layout, such as <a
href="http://www.w3.org/TR/CSS21/visuren.html#floats">floats</a> and <a
href="http://www.w3.org/TR/css3-multicol/">columns</a>. In return it gains
simple and powerful tools for distributing space and aligning content in
ways that webapps and complex web pages often need. The contents of a flex
container:
<ul>
<li> can be laid out in any <a href="#flex-direction-property">flow
direction</a> (leftwards, rightwards, downwards, or even upwards!)
<li> can have their display order <a
href="#flex-flow-row-reverse">reversed</a> or <a
href="#order-property">rearranged</a> at the style layer (i.e., visual
order can be independent of source and speech order)
<li> can be laid out linearly along a single (<a href="#main-axis"><i
title="main axis">main</i></a>) axis or <a
href="#flex-wrap-property">wrapped</a> into multiple lines along a
secondary (<a href="#cross-axis"><i title="cross axis">cross</i></a>)
axis
<li> can <a href="#flexibility">“flex” their sizes</a> to respond to
the available space
<li> can be <a href="#alignment">aligned</a> with respect to their
container or each other
<li> can be dynamically <a href="#visibility-collapse">collapsed</a> or
uncollapsed along the <a href="#main-axis"><i>main axis</i></a> while
preserving the container's <a href="#cross-size"><i>cross size</i></a>
</ul>
<div class=example>
<p> Here's an example of a catalog where each item has a title, an photo,
a description, and a purchase button. The designer's intention is that
each entry has the same overall size, that the photo be above the text,
and that the purchase buttons aligned at the bottom, regardless of the
length of the item's description. Flex layout makes many aspects of this
design easy:
<ul>
<li> The catalog uses flex layout to lay out rows of items horizontally,
and to ensure that items within a row are all equal-height. Each entry
is then itself a column flex container, laying out its contents
vertically.
<li> Within each entry, the source document content is ordered logically
with the title first, followed by the description and the photo. This
provides a sensible ordering for speech rendering and in non-CSS
browsers. For a more compelling visual presentation, however, ‘<a
href="#order"><code class=property>order</code></a>’ is used to pull
the image up from later in the content to the top, and ‘<a
href="#align-self"><code class=property>align-self</code></a>’ is used
to center it horizontally.
<li> An <a href="#auto-margins">‘<code class=css>auto</code>’
margin</a> above the purchase button forces it to the bottom within each
entry box, regardless of the height of that item's description.
</ul>
<pre>
<style>
#deals {
display: flex; /* Flex layout so items <a
href="#align-self"
title="Flex items stretch by default.">have equal height</a> */
flex-flow: row wrap; /* <a
href="http://dev.w3.org/csswg/css3-flexbox/#flex-flow-property">Allow items to wrap into multiple lines</a> */
}
.sale-item {
display: flex; /* Lay out each item using flex layout */
flex-flow: column; /* <a
href="#flex-flow-property">Lay out item's contents vertically</a> */
}
.sale-item > img {
order: -1; /* <a
href="#order-property">Shift image before other content (in visual order)</a> */
align-self: center; /* <a
href="#align-self">Center the image cross-wise (horizontally)</a> */
}
.sale-item > button {
margin-top: auto; /* <a
href="#auto-margins">Auto top margin pushes button to bottom</a> */
}
</style></pre>
<pre>
<section id='deals'>
<section class='sale-item'>
<h1>Computer Starter Kit</h1>
<p>This is the best computer money can buy, if you don't have much money.
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
<img src='images/computer.jpg'
alt='You get: a white computer with matching peripherals.'>
<button>BUY NOW</button>
</section>
<section class='sale-item'>
…
</section>
…
</section></pre>
<figure>
<div id=overview-example>
<div class=col></div>
<div class=col></div>
<div class=desc> <img
alt="You get: a white computer with matching keyboard and monitor."
src="images/computer.jpg">
<h1 style="font-size: 1.4em;">Computer Starter Kit</h1>
<p> This is the best computer money can buy, if you don't have much
money.
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
</div>
<div class=desc> <img alt="You get: beautiful ASCII art."
src="images/printer.png">
<h1 style="font-size: 1.4em;">Printer</h1>
<p> Only capable of printing ASCII art.
<ul>
<li>Paper and ink not included.
</ul>
</div>
<div class=buttons>
<div><button>BUY NOW</button></div>
<div><button>BUY NOW</button></div>
</div>
</div>
<figcaption> An example rendering of the code above. </figcaption>
</figure></div>
<h3 id=placement><span class=secno>1.2. </span> Module interactions</h3>
<p> This module extends the definition of the ‘<code
class=property>display</code>’ property <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, adding a new block-level and
new inline-level display type, and defining a new type of formatting
context along with properties to control its layout. It also defines a new
initial value for ‘<code class=property>min-width</code>’ and ‘<code
class=property>min-height</code>’. None of the properties defined in
this module apply to the ‘<code class=css>::first-line</code>’ or
‘<code class=css>::first-letter</code>’ pseudo-elements.
<h3 id=values><span class=secno>1.3. </span> Values</h3>
<p> This specification follows the <a
href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS
modules may expand the definitions of these value types: for example <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{CSS3VAL}}--></a>, when
combined with this module, expands the definition of the
<var><length></var> value type as used in this specification.
<p>In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the <a
href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">‘<code
class=css>inherit</code>’</a> keyword as their property value. For
readability it has not been repeated explicitly.
<h2 id=box-model><span class=secno>2. </span> Flex Layout Box Model and
Terminology</h2>
<p> An element with ‘<code class=css>display:flex</code>’ or ‘<code
class=css>display:inline-flex</code>’ is a <a
href="#flex-container"><i>flex container</i></a>. Children of a flex
container are called <a href="#flex-item"><i>flex items</i></a> and are
laid out using the flex layout model.
<p> Unlike block and inline layout, whose layout calculations are biased to
the <a href="http://www.w3.org/TR/css3-writing-modes/#abstract-box">block
and inline flow directions</a>, flex layout is biased to the <a
href="#flex-flow-property">flex flow</a> directions. To make it easier to
talk about flex layout, this section defines a set of flex flow–relative
terms. The ‘<a href="#flex-flow"><code
class=property>flex-flow</code></a>’ value determines how these terms
map to physical directions (top/right/bottom/left), axes
(vertical/horizontal), and sizes (width/height). <figure> <img alt=alt
height=277 src="images/flex-direction-terms.svg" width=665> <figcaption>
An illustration of the various directions and sizing terms as applied to a
‘<a href="#flex-flow-row"><code class=css>row</code></a>’ flex
container. </figcaption> </figure>
<dl id=main>
<dt class=axis title="main axis|main-axis">main axis
<dt class=axis>main dimension
<dd> The <dfn id=main-axis>main axis</dfn> of a flex container is the
primary axis along which <a href="#flex-item"><i>flex items</i></a> are
laid out. It extends in the <dfn id=main-dimension>main dimension</dfn>.
<dt class=side>main-start
<dt class=side>main-end
<dd> The <a href="#flex-item"><i>flex items</i></a> are placed within the
container starting on the <dfn id=main-start>main-start</dfn> side and
going toward the <dfn id=main-end>main-end</dfn> side.
<dt class=size>main size
<dt class=size>main size property
<dd> A <a href="#flex-item"><i>flex item</i></a>'s width or height,
whichever is in the <a href="#main-dimension"><i>main dimension</i></a>,
is the item's <dfn id=main-size>main size</dfn>. The <a
href="#flex-item"><i>flex item</i></a>'s <dfn
id=main-size-property>main size property</dfn> is either the ‘<code
class=property>width</code>’ or ‘<code
class=property>height</code>’ property, whichever is in the <a
href="#main-dimension"><i>main dimension</i></a>.
</dl>
<dl id=cross>
<dt class=axis title="cross axis|cross-axis">cross axis
<dt class=axis>cross dimension
<dd> The axis perpendicular to the <a href="#main-axis"><i>main
axis</i></a> is called the <dfn id=cross-axis>cross axis</dfn>. It
extends in the <dfn id=cross-dimension>cross dimension</dfn>.
<dt class=side>cross-start
<dt class=side>cross-end
<dd> <i>Flex lines</i> are filled with items and placed into the container
starting on the <dfn id=cross-start>cross-start</dfn> side of the flex
container and going toward the <dfn id=cross-end>cross-end</dfn> side.
<dt class=size>cross size
<dt class=size>cross size property
<dd> The width or height of a <a href="#flex-item"><i>flex item</i></a>,
whichever is in the <a href="#cross-dimension"><i>cross
dimension</i></a>, is the item's <dfn id=cross-size>cross size</dfn>. The
<dfn id=cross-size-property>cross size property</dfn> is whichever of
‘<code class=property>width</code>’ or ‘<code
class=property>height</code>’ that is in the <a
href="#cross-dimension"><i>cross dimension</i></a>.
</dl>
<h2 id=flex-containers><span class=secno>3. </span> Flex Containers: the <a
href="#display-flex">‘<code class=css>flex</code>’</a> and <a
href="#display-inline-flex">‘<code class=css>inline-flex</code>’</a>
‘<code class=property>display</code>’ values</h2>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td>display
<tr>
<th><a href="#values">New value</a>:
<td><dfn id=flex-value>flex</dfn> | <dfn
id=inline-flex-value>inline-flex</dfn>
</table>
<dl>
<dt><dfn id=display-flex>‘<code class=css>flex</code>’</dfn>
<dd> This value causes an element to generate a block-level <a
href="#flex-container"><i>flex container</i></a> box.
<dt><dfn id=display-inline-flex>‘<code
class=css>inline-flex</code>’</dfn>
<dd> This value causes an element to generate a inline-level <a
href="#flex-container"><i>flex container</i></a> box.
</dl>
<p> A <dfn id=flex-container>flex container</dfn> establishes a new <dfn
id=flex-formatting-context>flex formatting context</dfn> for its contents.
This is the same as establishing a block formatting context, except that
flex layout is used instead of block layout: floats do not intrude into
the flex container, and the flex container's margins do not collapse with
the margins of its contents. <a href="#flex-container"><i>Flex
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>
<p> Flex 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 flex layout. In particular:
<ul>
<li> all of the ‘<code class=css>column-*</code>’ properties in the
Multicol module have no effect on a flex container.
<li> ‘<code class=property>float</code>’ and ‘<code
class=property>clear</code>’ have no effect on a <a
href="#flex-item"><i>flex 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 flex
container, as this occurs <em title="">before</em> <a
href="#flex-item"><i>flex items</i></a> are determined.)
<li> ‘<code class=property>vertical-align</code>’ has no effect on a
flex item.
</ul>
<p> If an element's specified ‘<code class=property>display</code>’ is
‘<a href="#display-inline-flex"><code
class=css>inline-flex</code></a>’ and the element is floated or
absolutely positioned, the computed value of ‘<code
class=property>display</code>’ is <a href="#display-flex">‘<code
class=css>flex</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-flex"><code class=css>inline-flex</code></a>’ in
the "Specified Value" column and <a href="#display-flex">‘<code
class=css>flex</code>’</a> in the "Computed Value" column.
<h2 id=flex-items><span class=secno>4. </span> Flex Items</h2>
<p> The contents of a <a href="#flex-container"><i>flex container</i></a>
consists of zero or more <dfn id=flex-item title="flex item">flex
items</dfn>: each in-flow child of a <a href="#flex-container"><i>flex
container</i></a> becomes a <a href="#flex-item"><i>flex item</i></a>, and
each contiguous run of text that is directly contained inside a <a
href="#flex-container"><i>flex container</i></a> is wrapped in an
anonymous <a href="#flex-item"><i>flex item</i></a> element. However, an
anonymous flex 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 ‘<code
class=css>display:none</code>’.
<p class=note> Authors reading this spec may want to <a
href="#item-margins">skip past these box-generation details</a>.
<p> A <a href="#flex-item"><i>flex item</i></a> establishes a new
formatting context for its contents. The type of this formatting context
is determined by its ‘<code class=property>display</code>’ value, as
usual. The computed ‘<code class=property>display</code>’ of a <a
href="#flex-item"><i>flex item</i></a> 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, flex items are flex-level boxes, not block-level
boxes: they participate in their container's flex formatting context, not
in a block formatting context.
<p class=note> The ‘<code class=property>display</code>’ computation on
flex items as defined here is expected to be superseded by a future
specification that defines a new ‘<code class=property>display</code>’
value specific to flex items.
<div class=example>
<p>Examples of flex items:
<pre>
<div style="display:flex">
<!-- flex item: block child -->
<div id="item1">block</div>
<!-- flex item: floated element; floating is ignored -->
<div id="item2" style="float: left;">float</div>
<!-- flex item: anonymous block box around inline content -->
anonymous item 3
<!-- flex item: inline child -->
<span>
item 4
<!-- flex items do not split around blocks -->
<div id=not-an-item>item 4</div>
item 4
</span>
</div></pre>
</div>
<p> Some values of ‘<code class=property>display</code>’ trigger the
generation of anonymous boxes. For example, a misparented ‘<code
class=css>table-cell</code>’ child is fixed up by <a
href="http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes">generating
anonymous ‘<code class=css>table</code>’ and ‘<code
class=css>table-row</code>’ elements</a> around it. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> This fixup must occur
<em>before</em> a flex container's children are promoted to <a
href="#flex-item"><i>flex items</i></a>. For example, given two contiguous
child elements with ‘<code class=css>display:table-cell</code>’, an
anonymous table wrapper box around them becomes the <a
href="#flex-item"><i>flex item</i></a>.
<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
flex item determination run after these operations.
<p id=table-items> On a flex item with ‘<code class=css>display:
table</code>’, the table wrapper box becomes the <a
href="#flex-item"><i>flex item</i></a>, and the ‘<a href="#order"><code
class=property>order</code></a>’ and ‘<a href="#align-self"><code
class=property>align-self</code></a>’ properties apply to it. The
contents of any caption boxes contribute to the calculation of the table
wrapper box's min-content and max-content sizes. However, like ‘<code
class=property>width</code>’ and ‘<code
class=property>height</code>’, the ‘<a href="#flex"><code
class=property>flex</code></a>’ longhands apply to the table box as
follows: the <a href="#flex-item"><i>flex item</i></a>'s final size
is calculated by performing layout as if the distance between the table
wrapper box's edges and the table box's content edges were all part of the
table box's border+padding area, and the table box were the <a
href="#flex-item"><i>flex item</i></a>.