-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
3107 lines (2669 loc) · 204 KB
/
Overview.html
File metadata and controls
3107 lines (2669 loc) · 204 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><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Flexible Box Layout Module Level 1</title>
<link href=../default.css rel=stylesheet type=text/css>
<link href=../csslogo.ico rel="shortcut icon" type=image/x-icon>
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<script defer src=//test.csswg.org/harness/annotate.js#css-flexbox-1_dev type=text/javascript></script>
<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; }
a > 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>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=http://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>CSS Flexible Box Layout Module Level 1</h1>
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20140212>12 February 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/css-flexbox/>http://dev.w3.org/csswg/css-flexbox/</a><dt>Latest version:<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/css-flexbox/>http://dev.w3.org/csswg/css-flexbox/</a><dt>Previous Versions:<dd><a href=http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/ rel=previous>http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/</a><dd><a href=http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/ rel=previous>http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/</a><dd><a href=http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/ rel=previous>http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/</a><dd><a href=http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/ rel=previous>http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/</a><dd><a href=http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/ rel=previous>http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/</a><dd><a href=http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/ rel=previous>http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/</a>
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-flexbox%5D%20feedback">www-style@w3.org</a>
with subject line
“<kbd>[css-flexbox] <var>… message topic …</var></kbd>”(<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)<dt>Test Suite:<dd><a href=http://test.csswg.org/suites/css3-flexbox/nightly-unstable/>http://test.csswg.org/suites/css3-flexbox/nightly-unstable/</a><dt>Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://xanthir.com/contact/>Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://fantasai.inkedblade.net/contact>fantasai</a> (<span class="p-org org">Mozilla</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:ratan@microsoft.com>Rossen Atanassov</a> (<span class="p-org org">Microsoft</span>)<dt>Former Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:alexmog@microsoft.com>Alex Mogilevsky</a> (<span class="p-org org">Microsoft Corporation</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:dbaron@dbaron.org>L. David Baron</a> (<span class="p-org org">Mozilla Corporation</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:enndeakin@gmail.com>Neil Deakin</a> (<span class="p-org org">Mozilla Corporation</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:ian@hixie.ch>Ian Hickson</a> (<span class="p-org org">formerly of Opera Software</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:hyatt@apple.com>David Hyatt</a> (<span class="p-org org">formerly of Netscape Corporation</span>)<dt>Issues List:<dd>Tracked in spec, and in <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=Flexbox&resolution=---">Bugzilla</a></dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>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>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract>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.
<a href=http://www.w3.org/TR/CSS/>CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</p>
<h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=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=%5Bcss-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 “css-flexbox” in the subject,
preferably like this:
“[css-flexbox] <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>.</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of contents</span></h2>
<div data-fill-with=table-of-contents><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 <span><span class=css data-link-type=maybe title=flex>flex</span></span> and <span><span class=css data-link-type=maybe title=inline-flex>inline-flex</span></span> <span class=property data-link-type=propdesc title=display>display</span> 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 and Paddings</a><li><a href=#painting><span class=secno>4.3</span>
Flex Item Z-Ordering</a><li><a href=#visibility-collapse><span class=secno>4.4</span>
Collapsed Items</a></ul><li><a href=#flow-order><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 <span class=property data-link-type=propdesc title=flex-direction>flex-direction</span> property</a><li><a href=#flex-wrap-property><span class=secno>5.2</span>
Flex Line Wrapping: the <span class=property data-link-type=propdesc title=flex-wrap>flex-wrap</span> property</a><li><a href=#flex-flow-property><span class=secno>5.3</span>
Flex Direction and Wrap: the <span class=property data-link-type=propdesc title=flex-flow>flex-flow</span> shorthand</a><li><a href=#order-property><span class=secno>5.4</span>
Display Order: the <span class=property data-link-type=propdesc title=order>order</span> 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 <span class=property data-link-type=propdesc title=flex>flex</span> Shorthand</a><li><a href=#flex-common><span class=secno>7.2</span>
Common Values of <span class=property data-link-type=propdesc title=flex>flex</span></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 <span class=property data-link-type=propdesc title=flex-grow>flex-grow</span> property</a><li><a href=#flex-shrink-property><span class=secno>7.3.2</span>
The <span class=property data-link-type=propdesc title=flex-shrink>flex-shrink</span> property</a><li><a href=#flex-basis-property><span class=secno>7.3.3</span>
The <span class=property data-link-type=propdesc title=flex-basis>flex-basis</span> 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 <span data-link-for=margin data-link-type=value title=auto>auto</span> margins</a><li><a href=#justify-content-property><span class=secno>8.2</span>
Axis Alignment: the <span class=property data-link-type=propdesc title=justify-content>justify-content</span> property</a><li><a href=#align-items-property><span class=secno>8.3</span>
Cross-axis Alignment: the <span class=property data-link-type=propdesc title=align-items>align-items</span> and <span class=property data-link-type=propdesc title=align-self>align-self</span> properties</a><li><a href=#align-content-property><span class=secno>8.4</span>
Packing Flex Lines: the <span class=property data-link-type=propdesc title=align-content>align-content</span> 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><li><a href=#intrinsic-sizes><span class=secno>9.8</span>
Intrinsic Sizes</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=#acknowledgments><span class=secno></span>Acknowledgments</a><li><a href=#changes><span class=secno></span>Changes</a><li><a href=#conformance><span class=secno></span>
Conformance</a><ul class=toc><li><a href=#conventions><span class=secno></span>
Document conventions</a><li><a href=#conformance-classes><span class=secno></span>
Conformance classes</a><li><a href=#partial><span class=secno></span>
Partial implementations</a><li><a href=#experimental><span class=secno></span>
Experimental implementations</a><li><a href=#testing><span class=secno></span>
Non-experimental implementations</a></ul><li><a href=#references><span class=secno></span>
References</a><ul class=toc><li><a href=#normative><span class=secno></span>
Normative References</a><li><a href=#informative><span class=secno></span>
Informative References</a></ul><li><a href=#index><span class=secno></span>
Index</a><li><a href=#property-index><span class=secno></span>
Property index</a><li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>
Introduction</span><a class=self-link href=#intro></a></h2>
<p><em>This section is not normative.</em>
<p>
CSS 2.1 defined four layout modes — algorithms which determine
the size and position of boxes based on their relationships
with their sibling and ancestor boxes:
<p> <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 data-dfn-type=dfn data-export="" id=flex-layout>flex layout<a class=self-link href=#flex-layout></a></dfn>,
which is designed for laying out more complex applications and webpages.
<h3 class="heading settled heading" data-level=1.1 id=overview><span class=secno>1.1 </span><span class=content>
Overview</span><a class=self-link href=#overview></a></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 data-link-type=dfn href=#main-axis title="main axis">main</a>) axis or
<a href=#flex-wrap-property>wrapped</a> into multiple lines along a secondary (<a data-link-type=dfn href=#cross-axis title="cross axis">cross</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 data-link-type=dfn href=#main-axis title="main axis">main axis</a> while preserving the container’s <a data-link-type=dfn href=#cross-size title="cross size">cross size</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:
<p> <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 class=property data-link-type=propdesc href=#propdef-order title=order>order</a> is used to pull the image up from later in the content to the top,
and <a class=property data-link-type=propdesc href=#propdef-align-self title=align-self>align-self</a> is used to center it horizontally.
<li>
An <a href=#auto-margins><span class=css>auto</span> 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 class="heading settled heading" data-level=1.2 id=placement><span class=secno>1.2 </span><span class=content>
Module interactions</span><a class=self-link href=#placement></a></h3>
<p>
This module extends the definition of the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> property <a data-biblio-type=normative data-link-type=biblio href=#css21 title=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.
None of the properties defined in this module apply to the <span class=css data-link-type=maybe title=::first-line>::first-line</span> or <span class=css data-link-type=maybe title=::first-letter>::first-letter</span> pseudo-elements.
<h3 class="heading settled heading" data-level=1.3 id=values><span class=secno>1.3 </span><span class=content>
Values</span><a class=self-link href=#values></a></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 data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.
Value types not defined in this specification are defined in CSS Level 2 Revision 1 <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.
Other CSS modules may expand the definitions of these value types:
for example <a data-biblio-type=informative data-link-type=biblio href=#css3val title=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><span class=css data-link-type=maybe title=inherit>inherit</span></a> keyword as their property value. For readability it has not been repeated explicitly.
<h2 class="heading settled heading" data-level=2 id=box-model><span class=secno>2 </span><span class=content>
Flex Layout Box Model and Terminology</span><a class=self-link href=#box-model></a></h2>
<p>
A box with <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:flex</a> or <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:inline-flex</a> is a <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>.
Children of a flex container are called <a data-link-type=dfn href=#flex-item title="flex items">flex items</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 <dfn data-dfn-type=dfn data-noexport="" id=flex-direction title="flex direction">flex directions<a class=self-link href=#flex-direction></a></dfn>.
To make it easier to talk about flex layout,
this section defines a set of flex flow–relative terms.
The <a class=property data-link-type=propdesc href=#propdef-flex-flow title=flex-flow>flex-flow</a> value determines how these terms map
to physical directions (top/right/bottom/left),
axes (vertical/horizontal), and sizes (width/height).
</p><figure>
<img 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 class=css data-link-type=maybe href=#valuedef-row title=row>row</a> flex container.
</figcaption>
</figure>
<dl data-export="" id=main>
<dt class=axis>main axis
<dt class=axis>main dimension
<dd>
The <dfn data-dfn-type=dfn data-export="" id=main-axis title="main axis|main-axis">main axis<a class=self-link href=#main-axis></a></dfn> of a flex container is the primary axis along which <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> are laid out.
It extends in the <dfn data-dfn-type=dfn data-export="" id=main-dimension>main dimension<a class=self-link href=#main-dimension></a></dfn>.
<dt class=side>main-start
<dt class=side>main-end
<dd>
The <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> are placed within the container
starting on the <dfn data-dfn-type=dfn data-export="" id=main-start>main-start<a class=self-link href=#main-start></a></dfn> side
and going toward the <dfn data-dfn-type=dfn data-export="" id=main-end>main-end<a class=self-link href=#main-end></a></dfn> side.
<dt class=size>main size
<dt class=size>main size property
<dd>
A <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>'s width or height,
whichever is in the <a data-link-type=dfn href=#main-dimension title="main dimension">main dimension</a>,
is the item’s <dfn data-dfn-type=dfn data-export="" id=main-size>main size<a class=self-link href=#main-size></a></dfn>.
The <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>'s <dfn data-dfn-type=dfn data-export="" id=main-size-property>main size property<a class=self-link href=#main-size-property></a></dfn> is
either the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-width title=width>width</a> or <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-height title=height>height</a> property,
whichever is in the <a data-link-type=dfn href=#main-dimension title="main dimension">main dimension</a>.
</dl>
<dl data-export="" id=cross>
<dt class=axis>cross axis
<dt class=axis>cross dimension
<dd>
The axis perpendicular to the <a data-link-type=dfn href=#main-axis title="main axis">main axis</a> is called the <dfn data-dfn-type=dfn data-export="" id=cross-axis title="cross axis|cross-axis">cross axis<a class=self-link href=#cross-axis></a></dfn>.
It extends in the <dfn data-dfn-type=dfn data-export="" id=cross-dimension>cross dimension<a class=self-link href=#cross-dimension></a></dfn>.
<dt class=side>cross-start
<dt class=side>cross-end
<dd>
<a data-link-type=dfn href=#flex-line title="flex lines">Flex lines</a> are filled with items and placed into the container
starting on the <dfn data-dfn-type=dfn data-export="" id=cross-start>cross-start<a class=self-link href=#cross-start></a></dfn> side of the flex container
and going toward the <dfn data-dfn-type=dfn data-export="" id=cross-end>cross-end<a class=self-link href=#cross-end></a></dfn> side.
<dt class=size>cross size
<dt class=size>cross size property
<dd>
The width or height of a <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>,
whichever is in the <a data-link-type=dfn href=#cross-dimension title="cross dimension">cross dimension</a>,
is the item’s <dfn data-dfn-type=dfn data-export="" id=cross-size>cross size<a class=self-link href=#cross-size></a></dfn>.
The <dfn data-dfn-type=dfn data-export="" id=cross-size-property>cross size property<a class=self-link href=#cross-size-property></a></dfn> is
whichever of <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-width title=width>width</a> or <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-height title=height>height</a> that is in the <a data-link-type=dfn href=#cross-dimension title="cross dimension">cross dimension</a>.
</dl>
<h2 class="heading settled heading" data-level=3 id=flex-containers><span class=secno>3 </span><span class=content>
Flex Containers: the <a href=#display-flex><a class=css data-link-type=maybe href=#valuedef-flex title=flex>flex</a></a> and <a href=#display-inline-flex><a class=css data-link-type=maybe href=#valuedef-inline-flex title=inline-flex>inline-flex</a></a> <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> values</span><a class=self-link href=#flex-containers></a></h2>
<table class="definition propdef partial"><tr><th>Name:<td><a class=css-code data-link-type=property href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a><tr><th>New values:<td>flex | inline-flex</table>
<dl data-dfn-for=display data-dfn-type=value>
<dt><dfn class=css-code data-dfn-for=display data-dfn-type=value data-export="" id=valuedef-flex>flex<a class=self-link href=#valuedef-flex></a></dfn>
<dd>
This value causes an element to generate a block-level <a data-link-type=dfn href=#flex-container title="flex container">flex container</a> box.
<dt><dfn class=css-code data-dfn-for=display data-dfn-type=value data-export="" id=valuedef-inline-flex>inline-flex<a class=self-link href=#valuedef-inline-flex></a></dfn>
<dd>
This value causes an element to generate an inline-level <a data-link-type=dfn href=#flex-container title="flex container">flex container</a> box.
</dl>
<p>
A <dfn data-dfn-type=dfn data-export="" id=flex-container>flex container<a class=self-link href=#flex-container></a></dfn> establishes a new <dfn data-dfn-type=dfn data-export="" id=flex-formatting-context>flex formatting context<a class=self-link href=#flex-formatting-context></a></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 data-link-type=dfn href=#flex-container title="flex containers">Flex containers</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 data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>
The <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-overflow-3/#overflow0 title=overflow>overflow</a> property applies to <a data-link-type=dfn href=#flex-container title="flex containers">flex containers</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:
<p> <ul>
<li>
all of the <a class=property data-link-type=propdesc title=column-*>column-*</a> properties in the Multicol module have no effect on a flex container.
<li>
<a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-float title=float>float</a> and <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-clear title=clear>clear</a> have no effect on a <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>.
(However, the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-float title=float>float</a> property still affects the computed value of <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> on children of a flex container,
as this occurs <em>before</em> <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> are determined.)
<li>
<a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align title=vertical-align>vertical-align</a> has no effect on a flex item.
<li>
the <span class=css data-link-type=maybe title=::first-line>::first-line</span> and <span class=css data-link-type=maybe title=::first-letter>::first-letter</span> pseudo-elements do not apply to <a data-link-type=dfn href=#flex-container title="flex containers">flex containers</a>.
</ul>
<p>
If a box’s specified <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> is <a class=css data-link-type=maybe href=#valuedef-inline-flex title=inline-flex>inline-flex</a>
and the box is floated or absolutely positioned,
the computed value of <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> is <a href=#display-flex><a class=css data-link-type=maybe href=#valuedef-flex title=flex>flex</a></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 class=css data-link-type=maybe href=#valuedef-inline-flex title=inline-flex>inline-flex</a> in the "Specified Value" column
and <a href=#display-flex><a class=css data-link-type=maybe href=#valuedef-flex title=flex>flex</a></a> in the "Computed Value" column.
<h2 class="heading settled heading" data-level=4 id=flex-items><span class=secno>4 </span><span class=content>
Flex Items</span><a class=self-link href=#flex-items></a></h2>
<p>
The contents of a <a data-link-type=dfn href=#flex-container title="flex container">flex container</a> consists of zero or more <dfn data-dfn-type=dfn data-export="" id=flex-item title="flex item">flex items<a class=self-link href=#flex-item></a></dfn>:
each in-flow child of a <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>
becomes a <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>,
and each contiguous run of text that is directly contained inside a <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>
is wrapped in an anonymous <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>.
However, an anonymous flex item that contains only
<a href=http://www.w3.org/TR/CSS21/text.html#white-space-prop>white space</a>
(i.e. characters that can be affected by the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-3/#white-space title=white-space>white-space</a> property)
is not rendered, as if it were <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:none</a>.
<p class=note>
Authors reading this spec may want to
<a href=#item-margins>skip past these box-generation details</a>.
<p>
A <a data-link-type=dfn href=#flex-item title="flex item">flex item</a> establishes a new formatting context for its contents.
The type of this formatting context is determined by its <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> value, as usual.
The computed <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> of a <a data-link-type=dfn href=#flex-item title="flex item">flex item</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>
(except that internal table boxes are instead handled by anonymous box fixup, see below).
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 <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> computation on flex items as defined here
is expected to be superseded by a future specification
that defines a new <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> 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 <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display</a> trigger the generation of anonymous boxes.
For example, a misparented <span class=css data-link-type=maybe title=table-cell>table-cell</span> child is fixed up
by <a href=http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes>generating anonymous <span class=css data-link-type=maybe title=table>table</span> and <span class=css data-link-type=maybe title=table-row>table-row</span> boxes</a> around it. <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>
This fixup must occur <em>before</em> a flex container’s children are promoted to <a data-link-type=dfn href=#flex-item title="flex items">flex items</a>.
For example, given two contiguous child boxes with <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:table-cell</a>,
an anonymous table wrapper box around them becomes the <a data-link-type=dfn href=#flex-item title="flex item">flex item</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 <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display: table</a>, the table wrapper box becomes the <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>,
and the <a class=property data-link-type=propdesc href=#propdef-order title=order>order</a> and <a class=property data-link-type=propdesc href=#propdef-align-self title=align-self>align-self</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 <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-width title=width>width</a> and <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-height title=height>height</a>, the <a class=property data-link-type=propdesc href=#propdef-flex title=flex>flex</a> longhands apply to the table box as follows:
the <a data-link-type=dfn href=#flex-item title="flex item">flex item</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 data-link-type=dfn href=#flex-item title="flex item">flex item</a>.
<h3 class="heading settled heading" data-level=4.1 id=abspos-items><span class=secno>4.1 </span><span class=content>
Absolutely-Positioned Flex Children</span><a class=self-link href=#abspos-items></a></h3>
<p> An absolutely-positioned child of a <a data-link-type=dfn href=#flex-container title="flex container">flex container</a> does not participate in flex layout
beyond the <a href=#algo-flex-order>reordering step</a>.
<p> Its static position is calculated by first doing full flex layout without the absolutely-positioned children,
then positioning each absolutely-positioned child as if it were the sole <a data-link-type=dfn href=#flex-item title="flex item">flex item</a>
in the <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>,
assuming both the child and the <a data-link-type=dfn href=#flex-container title="flex container">flex container</a> were fixed size boxes of their used size.
<div class=example>
For example, by default, the static position of an absolutely positioned child aligns it to the main-start/cross-start corner,
corresponding to the default values of <a class=property data-link-type=propdesc href=#propdef-justify-content title=justify-content>justify-content</a> and <a class=property data-link-type=propdesc href=#propdef-align-content title=align-content>align-content</a> on the <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>.
Setting <a class=css data-link-type=propdesc href=#propdef-justify-content title=justify-content>justify-content:center</a> on the <a data-link-type=dfn href=#flex-container title="flex container">flex container</a>, however,
would center it in the main axis.
</div>
<h3 class="heading settled heading" data-level=4.2 id=item-margins><span class=secno>4.2 </span><span class=content>
Flex Item Margins and Paddings</span><a class=self-link href=#item-margins></a></h3>
<p>
The margins of adjacent <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> do not collapse.
Auto margins absorb extra space in the corresponding dimension and can be used for alignment
and to push adjacent flex items apart;
see <a href=#auto-margins>Aligning with <span class=css>auto</span> margins</a>.
<p>
Percentage margins and paddings on <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> are always resolved against their respective dimensions;
unlike blocks, they do not always resolve against the inline dimension of their containing block.
<h3 class="heading settled heading" data-level=4.3 id=painting><span class=secno>4.3 </span><span class=content>
Flex Item Z-Ordering</span><a class=self-link href=#painting></a></h3>
<p>
<a data-link-type=dfn href=#flex-item title="flex items">Flex items</a> paint exactly the same as inline blocks <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>,
except that <a class=property data-link-type=propdesc href=#propdef-order title=order>order</a>-modified document order is used in place of raw document order,
and <a href=http://www.w3.org/TR/CSS21/visuren.html#propdef-z-index><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-position-3/#z-index title=z-index>z-index</a></a>
values other than <a class=css-code data-link-for=z-index data-link-type=value title=auto>auto</a> create a stacking context
even if <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-position-3/#position title=position>position</a> is <span class=css data-link-type=maybe title=static>static</span>.
<p class=note>
Note: Descendants that are positioned outside a flex item still participate
in any stacking context established by the flex item.
<h3 class="heading settled heading" data-level=4.4 id=visibility-collapse><span class=secno>4.4 </span><span class=content>
Collapsed Items</span><a class=self-link href=#visibility-collapse></a></h3>
<p>
Specifying <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility:collapse</a> on a flex item
causes it to become a <dfn data-dfn-type=dfn data-noexport="" id=collapsed-flex-item title="collapsed flex item|collapsed">collapsed flex item<a class=self-link href=#collapsed-flex-item></a></dfn>,
producing an effect similar to <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility:collapse</a> on a table-row or table-column:
the collapsed flex item is removed from rendering entirely,
but leaves behind a "strut" that keeps the flex line’s cross-size stable.
Thus, if a flex container has only one flex line,
dynamically collapsing or uncollapsing items
is guaranteed to have no effect on the flex container’s <a data-link-type=dfn href=#cross-size title="cross size">cross size</a>
and won’t cause the rest of the page’s layout to "wobble".
Flex line wrapping <em>is</em> re-done after collapsing, however,
so the cross-size of a flex container with multiple lines might or might not change.
<p>
Though collapsed flex items aren’t rendered,
they do appear in the <a href=http://www.w3.org/TR/CSS21/intro.html#formatting-structure>formatting structure</a>.
Therefore, unlike on <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:none</a> items <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>,
effects that depend on a box appearing in the formatting structure
(like incrementing counters or running animations and transitions)
still operate on collapsed items.
<div class=example>
<p>In the following example,
a sidebar is sized to fit its content.
<a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility: collapse</a> is used to dynamically hide parts of a navigation sidebar
without affecting its width, even though the widest item (“Architecture”)
is in a collapsed section.
</p><figure>
<figcaption>Sample rendering for example code below</figcaption>
<div id=visibility-collapse-example>
<nav>
<ul>
<li id=nav-about><a href=#nav-about>About</a>
<ul>
<li><a href=#>History</a>
<li><a href=#>Mission</a>
<li><a href=#>People</a>
</ul>
<li id=nav-projects><a href=#nav-projects>Projects</a>
<ul>
<li><a href=#>Art</a>
<li><a href=#>Architecture</a>
<li><a href=#>Music</a>
</ul>
<li id=nav-interact><a href=#nav-interact>Interact</a>
<ul>
<li><a href=#>Blog</a>
<li><a href=#>Forums</a>
<li><a href=#>Events</a>
</ul>
</ul>
</nav>
<article>
Interesting Stuff to Read
</article>
</div>
</figure>
<pre> <style>
@media (min-width: 60em) {
/* <a href=http://www.w3.org/TR/css3-mediaqueries/#width>two column layout only when enough room</a> (relative to default text size) */
header + div { display: flex; }
#main {
flex: 1; /* <a href=#flexibility>Main takes up all remaining space</a> */
order: 1; /* <a href=#order-property>Place it after (to the right of) the navigation</a> */
min-width: 12em; /* Optimize main content area sizing */
}
}
/* menu items use flex layout so that visibility:collapse will work */
nav > ul > li {
display: flex;
flex-flow: column;
}
/* dynamically collapse submenus when not targetted */
nav > ul > li:not(:target):not(:hover) > ul {
visibility: collapse;
}
</style>
…
</header>
<div>
<article id="main">
Interesting Stuff to Read
</article>
<nav>
<ul>
<li id="nav-about"><a href="#nav-about">About</a>
…
<li id="nav-projects"><a href="#nav-projects">Projects</a>
<ul>
<li><a href="…">Art</a>
<li><a href="…">Architecture</a>
<li><a href="…">Music</a>
</ul>
<li id="nav-interact"><a href="#nav-interact">Interact</a>
…
</ul>
</nav>
</div>
<footer>
…
</pre>
</div>
<p>
To compute the size of the strut, flex layout is first performed with all items uncollapsed,
and then re-run with each collapsed item replaced by a strut that maintains
the original cross-size of the item’s original line.
See the <a href=#layout-algorithm>Flex Layout Algorithm</a>
for the normative definition of how <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility:collapse</a>
interacts with flex layout.
<p class=note>
Note that using <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility:collapse</a> on any flex items
will cause the flex layout algorithm to repeat partway through,
re-running the most expensive steps.
It’s recommended that authors continue to use <a class=css data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-display title=display>display:none</a> to hide items
if the items will not be dynamically collapsed and uncollapsed,
as that is more efficient for the layout engine.
(Since only part of the steps need to be repeated when <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility title=visibility>visibility</a> is changed,
however, 'visibility: collapse' is still recommended for dynamic cases.)
<h2 class="heading settled heading" data-level=5 id=flow-order><span class=secno>5 </span><span class=content>
Ordering and Orientation</span><a class=self-link href=#flow-order></a></h2>
<p>
The contents of a flex container can be laid out in any direction and in any order.
This allows an author to trivially achieve effects that would previously have required complex or fragile methods,
such as hacks using the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-float title=float>float</a> and <a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visuren.html#propdef-clear title=clear>clear</a> properties.
This functionality is exposed through the <a class=property data-link-type=propdesc href=#propdef-flex-direction title=flex-direction>flex-direction</a>, <a class=property data-link-type=propdesc href=#propdef-flex-wrap title=flex-wrap>flex-wrap</a>, and <a class=property data-link-type=propdesc href=#propdef-order title=order>order</a> properties.
<p class=note>
The reordering capabilities of flex layout intentionally affect
<em>only the visual rendering</em>,
leaving speech order and navigation based on the source order.
This allows authors to manipulate the visual presentation
while leaving the source order intact for non-CSS UAs and for
linear models such as speech and sequential navigation.
See <a href=#order-accessibility>Reordering and Accessibility</a>
and the <a href=#overview>Flex Layout Overview</a> for examples
that use this dichotomy to improve accessibility.
<p>
Authors <em>must not</em> use these techniques as a substitute for correct source ordering,
as that can ruin the accessibility of the document.
<h3 class="heading settled heading" data-level=5.1 id=flex-direction-property><span class=secno>5.1 </span><span class=content>
Flex Flow Direction: the <a class=property data-link-type=propdesc href=#propdef-flex-direction title=flex-direction>flex-direction</a> property</span><a class=self-link href=#flex-direction-property></a></h3>
<table class="definition propdef"><tr><th>Name:<td><dfn class=css-code data-dfn-type=property data-export="" id=propdef-flex-direction>flex-direction<a class=self-link href=#propdef-flex-direction></a></dfn><tr><th>Value:<td>row | row-reverse | column | column-reverse<tr><th>Initial:<td>row<tr><th>Applies to:<td><a data-link-type=dfn href=#flex-container title="flex containers">flex containers</a><tr><th>Inherited:<td>no<tr><th>Media:<td>visual<tr><th>Computed value:<td>specified value</table>
<p>
The <a class=property data-link-type=propdesc href=#propdef-flex-direction title=flex-direction>flex-direction</a> property specifies how <a data-link-type=dfn href=#flex-item title="flex items">flex items</a> are placed in the flex container,
by setting the direction of the flex container’s <a data-link-type=dfn href=#main-axis title="main axis">main axis</a>.
This determines the direction that flex items are laid out in.
<dl data-dfn-for=flex-direction data-dfn-type=value>
<dt><dfn class=css-code data-dfn-for=flex-direction data-dfn-type=value data-export="" id=valuedef-row>row<a class=self-link href=#valuedef-row></a></dfn>
<dd>
The flex container’s <a data-link-type=dfn href=#main-axis title="main axis">main axis</a> has the same orientation as the
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#inline-axis- title="inline axis">inline axis</a>
of the current <a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#writing-mode0 title="writing mode">writing mode</a>.
The <a data-link-type=dfn href=#main-start title=main-start>main-start</a> and <a data-link-type=dfn href=#main-end title=main-end>main-end</a> directions are equivalent to the
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#inline-start title=inline-start>inline-start</a> and
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#inline-end title=inline-end>inline-end</a> directions, respectively,
of the current <a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#writing-mode0 title="writing mode">writing mode</a>.
<dt><dfn class=css-code data-dfn-for=flex-direction data-dfn-type=value data-export="" id=valuedef-row-reverse>row-reverse<a class=self-link href=#valuedef-row-reverse></a></dfn>
<dd>
Same as <a class=css data-link-type=maybe href=#valuedef-row title=row>row</a>,
except the <a data-link-type=dfn href=#main-start title=main-start>main-start</a> and <a data-link-type=dfn href=#main-end title=main-end>main-end</a> directions are swapped.
<dt><dfn class=css-code data-dfn-for=flex-direction data-dfn-type=value data-export="" id=valuedef-column>column<a class=self-link href=#valuedef-column></a></dfn>
<dd>
The flex container’s <a data-link-type=dfn href=#main-axis title="main axis">main axis</a> has the same orientation as the
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#block-axis- title="block axis">block axis</a>
of the current <a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#writing-mode0 title="writing mode">writing mode</a>.
The <a data-link-type=dfn href=#main-start title=main-start>main-start</a> and <a data-link-type=dfn href=#main-end title=main-end>main-end</a> directions are equivalent to the
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#block-start title=block-start>block-start</a> and
<a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#block-end title=block-end>block-end</a> directions, respectively,
of the current <a data-link-type=dfn href=http://dev.w3.org/csswg/css-writing-modes-3/#writing-mode0 title="writing mode">writing mode</a>.
<dt><dfn class=css-code data-dfn-for=flex-direction data-dfn-type=value data-export="" id=valuedef-column-reverse>column-reverse<a class=self-link href=#valuedef-column-reverse></a></dfn>
<dd>
Same as <a class=css data-link-type=maybe href=#valuedef-column title=column>column</a>,
except the <a data-link-type=dfn href=#main-start title=main-start>main-start</a> and <a data-link-type=dfn href=#main-end title=main-end>main-end</a> directions are swapped.
</dl>
<p class=note>
The reverse values do not reverse box ordering;
like <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-writing-modes-3/#propdef-writing-mode title=writing-mode>writing-mode</a> and <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-writing-modes-3/#propdef-direction title=direction>direction</a> <a data-biblio-type=informative data-link-type=biblio href=#css3-writing-modes title=css3-writing-modes>[CSS3-WRITING-MODES]</a>,
they only change the direction of flow.
Painting order, speech order, and sequential navigation orders
are not affected.
<h3 class="heading settled heading" data-level=5.2 id=flex-wrap-property><span class=secno>5.2 </span><span class=content>
Flex Line Wrapping: the <a class=property data-link-type=propdesc href=#propdef-flex-wrap title=flex-wrap>flex-wrap</a> property</span><a class=self-link href=#flex-wrap-property></a></h3>
<table class="definition propdef"><tr><th>Name:<td><dfn class=css-code data-dfn-type=property data-export="" id=propdef-flex-wrap>flex-wrap<a class=self-link href=#propdef-flex-wrap></a></dfn><tr><th>Value:<td>nowrap | wrap | wrap-reverse<tr><th>Initial:<td>nowrap<tr><th>Applies to:<td><a data-link-type=dfn href=#flex-container title="flex containers">flex containers</a><tr><th>Inherited:<td>no<tr><th>Media:<td>visual<tr><th>Computed value:<td>specified value</table>