forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
3735 lines (2863 loc) · 139 KB
/
Copy pathOverview.html
File metadata and controls
3735 lines (2863 loc) · 139 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</title>
<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; }
</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, 22 May 2012</h2>
<dl>
<dt>This version:
<!--<dd><a href="http://www.w3.org/TR/2012/ED-css3-flexbox-20120522/">http://www.w3.org/TR/2012/WD-css3-flexbox-20120522/</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 versions:
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/">http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/">http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/">http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/</a>
<dd><a
href="http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/">http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/</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>Alex Mogilevsky, Microsoft Corporation, <a
href="mailto:alexmog@microsoft.com">alexmog@microsoft.com</a>
<dd>L. David Baron, Mozilla Corporation, <a
href="mailto:dbaron@dbaron.org">dbaron@dbaron.org</a>
<dt>Authors and former editors:
<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-->
<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="#placement"><span class=secno>1.1. </span> Module
interactions</a>
<li><a href="#values"><span class=secno>1.2. </span> Values</a>
</ul>
<li><a href="#box-model"><span class=secno>2. </span> Flex Layout Box
Model</a>
<li><a href="#display-flex"><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="#flex-item-margins"><span class=secno>4.1. </span> Flex
Item Margins</a>
<li><a href="#abspos-flex-items"><span class=secno>4.2. </span>
Out-of-flow Items</a>
<li><a href="#visibility-collapse"><span class=secno>4.3. </span>
Collapsed Items</a>
<li><a href="#min-size-auto"><span class=secno>4.4. </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="#flex-order-property"><span class=secno>5.4. </span>
Display Order: the ‘<code class=property>flex-order</code>’
property</a>
</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-examples"><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="#flex-pack-property"><span class=secno>8.2. </span> Axis
Alignment: the ‘<code class=property>flex-pack</code>’ property</a>
<li><a href="#flex-align-property"><span class=secno>8.3. </span>
Cross-axis Alignment: the ‘<code class=property>flex-align</code>’
and ‘<code class=property>flex-item-align</code>’ properties</a>
<li><a href="#flex-line-pack-property"><span class=secno>8.4. </span>
The ‘<code class=property>flex-line-pack</code>’ property</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="#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>
<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: block layout, designed for laying out documents;
inline layout, designed for laying out text; table layout, designed for
laying out information in a tabular format; and positioned layout,
designed for very explicit positioning without much regard for other
elements in the document. This module introduces a new layout mode, flex
layout, which is designed for laying out more complex applications and
webpages.
<p>Flex layout is superficially similar to block layout. It lacks many of
the more complex text or document-formatting properties that can be used
in block layout, such as ‘<code class=property>float</code>’ and ‘<a
href="#flex-flow-column"><code class=property>columns</code></a>’, but
in return it gains more simple and powerful tools for aligning its
contents in ways that webapps and complex web pages often need.
<p>The contents of a flex container can be laid out in any direction (left,
right, down, or even up!), can have their order swapped around dynamically
(i.e., display order is independent of source order), and can "flex" their
sizes and positions to respond to the available space. If a flex container
is <a href="#multi-line"><i>multi-line</i></a>, the flex items flow in two
dimensions, wrapping into separate lines in a fashion similar to how text
is wrapped into multiple lines.
<div class=example>
<p>For example, the following HTML snippet uses a flex container to create
a toolbar with icons. The flex container is horizontal, and the
children's widths don't fill the flex container's width, so the
additional space is distributed around and between the children. As the
flex container grows (perhaps because the user is viewing the page on a
wider screen), the children spread out evenly and automatically:
<pre>
<ul>
<li><button><img src='new.svg' alt="New"></button></li>
<li><button><img src='upload.svg' alt="Upload"></button></li>
<li><button><img src='save.svg' alt="Save"></button></li>
<li><button><img src='trash.svg' alt="trash"></button></li>
</ul>
<style>
ul { display: flex; flex-pack: distribute; }
/* Irrelevant styling for this example removed. */
</style></pre>
<div class=figure> <img alt height=140 src="images/toolbar-example.svg"
width=400>
<p class=caption>Example rendering of the above code snippet, at two
different flex container widths.
</div>
</div>
<h3 id=placement><span class=secno>1.1. </span> Module interactions</h3>
<p>This module extends the definition of the ‘<code
class=property>display</code>’ property.
<h3 id=values><span class=secno>1.2. </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
[[CSS3VALUES]], when combined with this module, expands the definition of
the <length> 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</h2>
<p>An element with ‘<code class=css>display:flex</code>’ or ‘<code
class=css>display:inline-flex</code>’ is a <dfn id=flex-container>flex
container</dfn>. 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 layout, which is normally biased towards laying things out
vertically, and inline layout, which is normally biased toward laying
things out horizontally, the flex layout algorithm is agnostic as to the
direction the flex container happens to be laid out in. To make it easier
to talk about flex layout in a general way, we will define several
direction-agnostic terms here to make the rest of the spec easier to read
and understand.
<div class=figure> <img alt height=300
src="images/flex-direction-terms.svg" width=510>
<p class=caption>An illustration of the various directions and sizing
terms used in this specification, respectively for ‘<a
href="#flex-flow-row"><code class=css>row</code></a>’ and ‘<a
href="#flex-flow-column"><code class=css>column</code></a>’ flex
containers.
</div>
<p> The <dfn id=main-axis>main axis</dfn> of a flex container is the axis
along which <a href="#flex-item"><i>flex items</i></a> are laid out. The
<a href="#flex-item"><i>flex items</i></a> are ordered such that they
start on the <dfn id=main-start>main-start</dfn> side of the flex
container, and go toward the <dfn id=main-end>main-end</dfn> side. A <a
href="#flex-item"><i>flex item's</i></a> width or height, whichever is in
the <i>main dimension</i>, is the item's <dfn id=main-size>main
size</dfn>. The <a href="#flex-item"><i>flex item's</i></a> <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 <i>main dimension</i>.
<p> The axis perpendicular to the <a href="#main-axis"><i>main axis</i></a>
is called the <dfn id=cross-axis>cross axis</dfn>, and similarly has <dfn
id=cross-start>cross-start</dfn> and <dfn id=cross-end>cross-end</dfn>
sides defined. The width or height of a <a href="#flex-item"><i>flex
item</i></a>, whichever is in the <i>cross dimension</i>, is the item's
<dfn id=cross-size>cross size</dfn>, and similarly 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 <i>cross dimension</i>.
<p> The contents of a flex container can be easily and powerfully
manipulated with a handful of properties. Most significantly, <a
href="#flex-item"><i>flex items</i></a> can "flex" their <a
href="#main-size"><i>main size</i></a> by using the ‘<a
href="#flex"><code class=property>flex</code></a>’ property. This
"flexing" allows the items to get bigger or smaller based on the available
space in the page. If there is leftover space in the flex container after
all of the <a href="#flex-item"><i>flex items</i></a> have finished
flexing, the items can be aligned, centered, or distributed with the ‘<a
href="#flex-pack"><code class=property>flex-pack</code></a>’ property.
<a href="#flex-item"><i>Flex items</i></a> can also be completely
rearranged within the flex container with the ‘<a
href="#flex-order"><code class=property>flex-order</code></a>’ property.
<p> In the <a href="#cross-axis"><i>cross axis</i></a>, <a
href="#flex-item"><i>flex items</i></a> can either "stretch" to fill the
available space or be aligned within the space with the ‘<a
href="#flex-align"><code class=property>flex-align</code></a>’ property.
If a flex container is <a href="#multi-line"><i>multi-line</i></a>, new
lines are added in the <a href="#cross-end"><i>cross-end</i></a>
direction, and can similarly be aligned, centered, or distributed within
the flex container with the ‘<a href="#flex-line-pack"><code
class=property>flex-line-pack</code></a>’ property.
<h2 id=display-flex><span class=secno>3. </span> Flex Containers: the ‘<a
href="#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=display-flex>flex</dfn> | <dfn
id=display-inline-flex>inline-flex</dfn>
</table>
<p> An element whose computed ‘<code class=property>display</code>’ is
either ‘<a href="#flex"><code class=css>flex</code></a>’ or ‘<a
href="#display-inline-flex"><code class=css>inline-flex</code></a>’ is a
flex container, and 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. Additionally, each of the <a href="#flex-item"><i>flex
items</i></a> establishes a new formatting context for its contents.
<p> The ‘<a href="#flex"><code class=css>flex</code></a>’ value makes
the flex container a block-level element. The ‘<a
href="#display-inline-flex"><code class=css>inline-flex</code></a>’
value makes the flex container an atomic inline-level element.
<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>. Using ‘<code
class=property>float</code>’ on an element still causes that element's
‘<code class=property>display</code>’ property to compute to ‘<code
class=css>block</code>’, and thus ‘<code
class=property>float</code>’ may affect whether an element becomes a
flex item or is wrapped in one. (See <a
href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter
9.7</a>.)
<li> ‘<code class=property>vertical-align</code>’ has no effect on a
flex item.
</ul>
<p> If an element's specified value for ‘<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="#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="#flex"><code
class=css>flex</code></a>’ in the "Computed Value" column.
<p> The baseline of a flex container is determined as follows:
<ul>
<li> If any of the <a href="#flex-item"><i>flex items</i></a> on the flex
container's first line (after reordering with ‘<a
href="#flex-order"><code class=property>flex-order</code></a>’) have a
computed value of ‘<a href="#flex-align-baseline"><code
class=css>baseline</code></a>’ for ‘<a href="#flex-item-align"><code
class=property>flex-item-align</code></a>’, the flex container's
baseline is the baseline of those <a href="#flex-item"><i>flex
items</i></a>.
<li> Otherwise, if the flex container has at least one <a
href="#flex-item"><i>flex item</i></a>, and the baseline of its first <a
href="#flex-item"><i>flex item</i></a> (after reordering with ‘<a
href="#flex-order"><code class=property>flex-order</code></a>’) is
parallel to the flex container's <i>main-axis</i>, the flex container's
baseline is the baseline of its first <a href="#flex-item"><i>flex
item</i></a>.
<li> Otherwise, the flex container's baseline is the "after" edge of its
content box.
</ul>
<h2 id=flex-items><span class=secno>4. </span> Flex Items</h2>
<p> The flex layout algorithm operates on boxes generated by <dfn
id=flex-item title="flex item|flex item's">flex items</dfn>. Each of the
following becomes a <a href="#flex-item"><i>flex item</i></a>:
<ol>
<li> A block-level child of a flex container
<li> An atomic inline-level child of a flex container
<li> An HTML <code><img></code>, <code><canvas></code>,
<code><svg></code>, <code><math></code>, <code><audio></code>,
<code><video></code>, <code><iframe></code>,
<code><object></code>, <code><embed></code>,
<code><applet></code>, <code><progress></code>,
<code><meter></code>, <code><input></code>,
<code><button></code>, <code><select></code>, or
<code><textarea></code> element. <span class=note>Note: In other
words, any element that is "intended to be" a replaced element, even if
it becomes non-replaced (like an <code><object></code> that doesn't
load and is replaced by its contents).</span>
<li> An anonymous block wrapped around a contiguous run of non-replaced
inline child elements. However, if the anonymous block would contain
solely an anonymous inline containing only whitespace, the box is not
generated, as if it had ‘<code class=css>display:none</code>’.
</ol>
<p> Some values of ‘<code class=property>display</code>’ trigger the
generation of anonymous boxes. For example, a ‘<code
class=css>table-cell</code>’ child of a block container is fixed up by
generating ‘<code class=css>table</code>’ and ‘<code
class=css>table-row</code>’ elements around it. This fixup must occur
<em>before</em> a flex container's contents are checked to see if it's
necessary to generate anonymous flex items.
<p> The computed value for ‘<code class=property>display</code>’ for
elements that are <a href="#flex-item"><i>flex items</i></a> must be
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>. <span class=note>This is expected to be superseded by a future
specification that defines a new ‘<code class=property>display</code>’
value for flex items.</span>
<div class=example>
<p>Examples of flex items:
<pre>
<div style="display:flex">
<!-- flex item: block-level child -->
<div id="item1">block</div>
<!-- not a flex item, because it's out-of-flow -->
<!-- however, the placeholder it leaves behind is -->
<div id="not-an-item-A" style="position: absolute;">block</div>
<!-- flex item: block-level child -->
<div id="item3" style="display:table">table</div>
<!-- flex item: anonymous table wrapped around table-cell -->
<div id="item4" style="display:table-cell">table-cell</div>
<!-- flex item: anonymous block box around inline content -->
anonymous item 5
<!-- flex item: block-level child -->
<div id="item6">block</div>
<!-- flex item: anonymous block around inline content -->
item 7
<span>
item 7
<div id="not-an-item-B">item 7</div>
item 7
</span>
<!-- flex item: block-level replaced element -->
<iframe id="item8" style="display:block;"></iframe>
<!-- flex item: inline-level replaced element -->
<img id="item9">
<!-- flex item: atomic inline-level element -->
<button id="item10">button</button>
<!-- flex item: inline-table -->
<div id="item11" style="display:inline-table">table</div>
<!-- flex item: floated inline, which changes to a block -->
<span id="item12" style="float: left;">span</span>
</div></pre>
<p> Notice that block element "not-an-item-B" is not a flex item, because
it's not a child element of the flex container, even though the inline
<span> is eventually broken around it by Block Layout. Similarly, the
block element "not-an-item-A" is not a flex item, because absolutely
positioned children have special treatment.
</div>
<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.
<h3 id=flex-item-margins><span class=secno>4.1. </span> Flex Item Margins</h3>
<p> The margins of adjacent <a href="#flex-item"><i>flex items</i></a> do
not collapse. Auto margins absorb extra space in that dimension and can be
used for alignment and to push adjacent flex items apart; see <a
href="#auto-margins">Aligning with ‘<code class=css>auto</code>’
margins</a>.
<h3 id=abspos-flex-items><span class=secno>4.2. </span> Out-of-flow Items</h3>
<p> Absolutely positioned children of a flex container are not themselves
<a href="#flex-item"><i>flex items</i></a>, but they leave behind
"placeholders" in their normal position in the box tree. These
placeholders are atomic inline boxes with a width, height, and flex of
‘<code class=css>0</code>’, becoming zero-sized flex items that
otherwise interact normally with the flex layout algorithm.
<p> The <i>static position</i> of an absolutely positioned child of a flex
container (the position when the ‘<code
class=property>top</code>’/‘<code
class=property>right</code>’/‘<code
class=property>bottom</code>’/‘<code class=property>left</code>’
properties are ‘<a href="#flex-item-align-auto"><code
class=css>auto</code></a>’), then, is the final position of its
corresponding placeholder, after flex layout has been performed.
<p class=note> Note: In most cases, this means that absolutely-positioned
items have no effect on flex layout. However, when the flex container has
‘<code class=css>flex-pack:justify</code>’ or ‘<code
class=css>flex-pack:distribute</code>’, each placeholder flex item will
cause there to be two packing spaces where there would otherwise be only
one, possibly resulting in increased space between two "real" items.
<h3 id=visibility-collapse><span class=secno>4.3. </span> Collapsed Items</h3>
<p> Specifying ‘<code class=css>visibility:collapse</code>’ on a flex
item causes it to become a <dfn id=collapsed-flex-item
title="collapsed flex item|collapsed">collapsed flex item</dfn>, producing
an effect similar to ‘<code class=css>visibility:collapse</code>’ on a
table-row or table-column: the collapsed element 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 href="#cross-size"><i>cross size</i></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
struture</a>. Therefore, unlike on ‘<code
class=css>display:none</code>’ items <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, effects that depend on an
element appearing in the formatting structure (like incrementing counters
or running animations and transitions) still operate on collapsed items.
<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 ‘<code
class=css>visibility:collapse</code>’ interacts with flex layout.
<p class=note> Note that using ‘<code
class=css>visibility:collapse</code>’ 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 ‘<code
class=css>display:none</code>’ to hide items if the items will not be
dynamically collapsed and uncollapsed, as that is more efficient for the
layout engine.
<h3 id=min-size-auto><span class=secno>4.4. </span> Implied Minimum Size of
Flex Items</h3>
<p> To provide a more reasonable default minimum size for flex containers,
this specification introduces a new <a href="#min-auto">‘<code
class=css>auto</code>’</a> value as the initial value of the ‘<code
class=property>min-width</code>’ and ‘<code
class=property>min-height</code>’ properties defined in CSS 2.1. <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td>min-width, min-height
<tr>
<th><a href="#values">New value</a>:
<td>auto
<tr>
<th>New Initial Value:
<td><a href="#min-auto"><strong
title="min-width/height:auto">auto</strong></a>
<tr>
<th>New Computed Value:
<td>the percentage as specified or the absolute length or a keyword
</table>
<dl>
<dt><dfn id=min-auto title="min-width/height:auto">auto</dfn>
<dd> On a flex item, this keyword indicates a minimum size of the
min-content size.
<p class=note> It is intended that this will compute to the ‘<code
class=css>min-content</code>’ keyword when the specification defining
it (<a
href="http://www.w3.org/TR/css3-writing-modes/#intrinsic-sizing">Writing
Modes Appendix D</a>) is sufficiently mature.
<p> On any other element, this keyword computes to ‘<code
class=css>0</code>’ (unless otherwise defined by a future
specification).
</dl>
<h2 id=ordering-and-orientation><span class=secno>5. </span> Ordering and
Orientation</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 ‘<code class=property>float</code>’ and ‘<code
class=property>clear</code>’ properties. This functionality is exposed
through the ‘<a href="#flex-direction"><code
class=property>flex-direction</code></a>’, ‘<a href="#flex-wrap"><code
class=property>flex-wrap</code></a>’, and ‘<a href="#flex-order"><code
class=property>flex-order</code></a>’ properties.
<h3 id=flex-direction-property><span class=secno>5.1. </span> Flex Flow
Direction: the ‘<a href="#flex-direction"><code
class=property>flex-direction</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=flex-direction>flex-direction</dfn>
<tr>
<th><a href="#values">Value</a>:
<td>row | row-reverse | column | column-reverse
<tr>
<th>Initial:
<td>row
<tr>
<th>Applies To:
<td>flex containers
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
<tr>
<th>Animatable:
<td>no
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p> The ‘<a href="#flex-direction"><code
class=property>flex-direction</code></a>’ property specifies how <a
href="#flex-item"><i>flex items</i></a> are placed in the flex container,
by setting the direction of the flex container's <a
href="#main-axis"><i>main axis</i></a>. This determines the direction that
flex items are laid out in.
<dl>
<dt><dfn id=flex-flow-row>‘<code class=css>row</code>’</dfn>
<dd> The flex container's <a href="#main-axis"><i>main axis</i></a> has
the same orientation as the inline axis of the current <a
href="http://www.w3.org/TR/css3-writing-modes/#writing-mode">writing
mode</a> (the primary direction that text is laid out in). The <a
href="#main-start"><i>main-start</i></a> and <a
href="#main-end"><i>main-end</i></a> directions are equivalent to the <a
href="http://www.w3.org/TR/css3-writing-modes/#start">start</a> and <a
href="http://www.w3.org/TR/css3-writing-modes/#end">end</a> directions,
respectively, of the current <a
href="http://www.w3.org/TR/css3-writing-modes/#writing-mode">writing
mode</a>.
<dt><dfn id=flex-flow-row-reverse>‘<code
class=css>row-reverse</code>’</dfn>
<dd> Same as ‘<a href="#flex-flow-row"><code
class=css>row</code></a>’, except the <a
href="#main-start"><i>main-start</i></a> and <a
href="#main-end"><i>main-end</i></a> directions are swapped.
<dt><dfn id=flex-flow-column>‘<code class=css>column</code>’</dfn>
<dd> The flex container's <a href="#main-axis"><i>main axis</i></a> has
the same orientation as the block axis of the current <a
href="http://www.w3.org/TR/css3-writing-modes/#writing-mode">writing
mode</a> (the primary direction that blocks are laid out in). The <a
href="#main-start"><i>main-start</i></a> and <a
href="#main-end"><i>main-end</i></a> directions are equivalent to the <a
href="http://www.w3.org/TR/css3-writing-modes/#before">before</a> and <a
href="http://www.w3.org/TR/css3-writing-modes/#after">after</a>
directions, respectively, of the current <a
href="http://www.w3.org/TR/css3-writing-modes/#writing-mode">writing
mode</a>.
<dt><dfn id=flex-flow-column-reverse>‘<code
class=css>column-reverse</code>’</dfn>
<dd> Same as ‘<a href="#flex-flow-column"><code
class=css>column</code></a>’, except the <a
href="#main-start"><i>main-start</i></a> and <a
href="#main-end"><i>main-end</i></a> directions are swapped.
</dl>
<h3 id=flex-wrap-property><span class=secno>5.2. </span> Flex Line
Wrapping: the ‘<a href="#flex-wrap"><code
class=property>flex-wrap</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=flex-wrap>flex-wrap</dfn>
<tr>
<th><a href="#values">Value</a>:
<td>nowrap | wrap | wrap-reverse
<tr>
<th>Initial:
<td>nowrap
<tr>
<th>Applies To:
<td>flex containers
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
<tr>
<th>Animatable:
<td>no
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p> The ‘<a href="#flex-wrap"><code
class=property>flex-wrap</code></a>’ property controls whether the flex
container is <a href="#single-line"><i>single-line</i></a> or <a
href="#multi-line"><i>multi-line</i></a>, and the direction of the
<i>cross-axis</i>, which determines the direction new lines are stacked
in.
<dl>
<dt><dfn id=flex-flow-nowrap>‘<code class=css>nowrap</code>’</dfn>