-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.html
More file actions
1746 lines (1345 loc) · 67.2 KB
/
Overview.html
File metadata and controls
1746 lines (1345 loc) · 67.2 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/css-module/default.css" rel=stylesheet
type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet
type="text/css">
<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, 24 November 2011</h2>
<dl>
<dt>This version:
<dd><!-- <a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20111124/">http://www.w3.org/TR/2011/WD-css3-flexbox-20111124/</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>
<dt>Previous version:
<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>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> © 2011 <a
href="http://www.w3.org/"><acronym
title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym
title="Massachusetts Institute of Technology">MIT</acronym></a>, <a
href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></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 flexbox layout model, the children of a box are laid out either
horizontally or vertically, and unused space can be assigned to a
particular child or distributed among the children by assignment of "flex"
to the children that should expand. 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>
<li><a href="#box-model"><span class=secno>2. </span> The Flexbox Box
Model</a>
<ul class=toc>
<li><a href="#display-flexbox"><span class=secno>2.1. </span> New values
for ‘<code class=property>display</code>’ property</a>
<li><a href="#flex-items"><span class=secno>2.2. </span> Flexbox
Items</a>
<ul class=toc>
<li><a href="#abspos-flexbox-items"><span class=secno>2.2.1. </span>
Positioning Absolutely Positioned Flexbox Items</a>
</ul>
</ul>
<li><a href="#ordering-orientation"><span class=secno>3. </span> Ordering
and Orientation</a>
<ul class=toc>
<li><a href="#flex-flow"><span class=secno>3.1. </span> Flexbox Flow
Direction: the ‘<code class=property>flex-flow</code>’
property</a>
<li><a href="#flex-order"><span class=secno>3.2. </span> Display Order:
the ‘<code class=property>flex-order</code>’ property</a>
</ul>
<li><a href="#flexibility"><span class=secno>4. </span> Flexibility</a>
<ul class=toc>
<li><a href="#flex-function"><span class=secno>4.1. </span> The
‘<code class=css>flex()</code>’ function</a>
<li><a href="#resolving-flexible-lengths"><span class=secno>4.2. </span>
Resolving Flexible Lengths</a>
</ul>
<li><a href="#alignment"><span class=secno>5. </span> Alignment</a>
<ul class=toc>
<li><a href="#flex-pack"><span class=secno>5.1. </span> Main Axis
Alignment: the ‘<code class=property>flex-pack</code>’
property</a>
<li><a href="#flex-align"><span class=secno>5.2. </span> Cross Axis
Alignment: the ‘<code class=property>flex-align</code>’
property</a>
</ul>
<li><a href="#multiline"><span class=secno>6. </span> Multi-line
Flexbox</a>
<ul class=toc>
<li><a href="#flex-line-pack"><span class=secno>6.1. </span>
‘<code class=property>flex-line-pack</code>’ property</a>
</ul>
<li><a href="#layout-algorithm"><span class=secno>7. </span> Flexbox
Layout Algorithm</a>
<li><a href="#pagination"><span class=secno>8. </span> Page breaks in
flexbox</a>
<li><a href="#layout-interface"><span class=secno>9. </span> Box
Properties and Sizing</a>
<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>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 and
simple applications; 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, flexbox layout, which is designed for laying out more complex
applications and webpages.
<p>Flexbox 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 ‘<code
class=property>columns</code>’, 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 flexbox can be laid out in any direction, can have
their order swapped around dynamically, and can "flex" their sizes and
positions to respond to the available space. If a flexbox is <a
href="#multi-line"><i>multi-line</i></a>, the flexbox items flow in two
dimensions, wrapping into separate lines in a fashion similar to how text
is wrapped into multiple lines. The direction that these lines are stacked
in can also be controlled explicitly, relative either to the current
writing mode (logical directions) or explicit physical directions.
<h2 id=box-model><span class=secno>2. </span> The Flexbox Box Model</h2>
<p>An element with ‘<code class=css>display:flexbox</code>’ or
‘<code class=css>display:inline-flexbox</code>’ is a <dfn
id=flexbox>flexbox</dfn>. Block-level children of a flexbox, and some
other types of children, are called <dfn id=flexbox-item
title="flexbox item|flexbox items|flexbox item's">flexbox items</dfn> and
are laid out using the flexbox box model. <span class=note>(See the <a
href="#flex-items">Flexbox Items</a> chapter, below, for specifics on
which children are <a href="#flexbox-item"><i>flexbox items</i></a>
directly and which children are instead wrapped in anonymous boxes which
are then <a href="#flexbox-item"><i>flexbox items</i></a>)</span>
<p>The flexbox layout algorithm is agnostic as to the physical direction
the flexbox happens to be laid out in, so we will define several
direction-agnostic terms here to make the rest of the spec easier to read
and understand. The <dfn id=main-axis>main axis</dfn> of a flexbox is the
axis on which <a href="#flexbox-item"><i>flexbox items</i></a> are laid
out along. The <a href="#flexbox-item"><i>flexbox items</i></a> are
ordered such that they start on the <dfn id=main-start>main-start</dfn>
side of the flexbox, and go toward the <dfn id=main-end>main-end</dfn>
side. A <a href="#flexbox-item"><i>flexbox item's</i></a> width or height,
whichever is in the <a href="#main-axis"><i>main axis</i></a>, is the
item's <dfn id=main-size>main size</dfn>. The <a
href="#flexbox-item"><i>flexbox item's</i></a> ‘<code
class=property>width</code>’ or ‘<code
class=property>height</code>’ property, specifically, that is in the
<a href="#main-axis"><i>main axis</i></a> is the item's <dfn
id=main-size-property>main size property</dfn>. These terms are mapped to
physical directions based on the first keyword in the ‘<a
href="#flex-flow0"><code class=property>flex-flow</code></a>’
property.
<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>
directions and sides defined. The width or height of a <a
href="#flexbox-item"><i>flexbox item</i></a>, whichever is in the <a
href="#cross-axis"><i>cross axis</i></a>, is the item's <dfn
id=cross-size>cross size</dfn>, and similarly the actual ‘<code
class=property>width</code>’ or ‘<code
class=property>height</code>’ property, whichever is in the <a
href="#cross-axis"><i>cross axis</i></a>, is the item's <dfn
id=cross-size-property>cross size property</dfn>. These terms are mapped
to physical directions based on the orientation of the <a
href="#main-axis"><i>main axis</i></a> and the second keyword in the
‘<a href="#flex-flow0"><code
class=property>flex-flow</code></a>’ property.
<p>The contents of a flexbox can be easily and powerfully manipulated with
a handful of properties. Most significantly, <a
href="#flexbox-item"><i>flexbox items</i></a> can "flex" their <a
href="#main-size"><i>main size</i></a> by using the ‘<code
class=css>flex()</code>’ function in the ‘<code
class=property>width</code>’ or ‘<code
class=property>height</code>’ 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 flexbox after all of the <a
href="#flexbox-item"><i>flexbox items</i></a> have finished flexing, the
items can be aligned, centered, or distributed with the ‘<a
href="#flex-pack0"><code class=property>flex-pack</code></a>’
property. <a href="#flexbox-item"><i>Flexbox items</i></a> can also be
completely rearranged within the flexbox with the ‘<a
href="#flex-order0"><code class=property>flex-order</code></a>’
property.
<p>In the <a href="#cross-axis"><i>cross axis</i></a>, <a
href="#flexbox-item"><i>flexbox items</i></a> can either "flex" to fill
the available space or be aligned within the space with the ‘<a
href="#flex-align0"><code class=property>flex-align</code></a>’
property. If a flexbox 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 flexbox with the ‘<a href="#flex-line-pack0"><code
class=property>flex-line-pack</code></a>’ property.
<p>Similar to other layout modes such as table layout, a flexbox acts like
a block when placed into elements using other layout modes. Inline
flexboxes act like inline-blocks.
<div class=example>
<p>For example, the following HTML snippet declares a flexbox with a few
children. The flexbox is horizontal, and the children's widths don't fill
the flexbox's width, so the additional space is distributed between the
children. The flexbox's height isn't explicitly specified, so it shrinks
to the height of its tallest child and centers the other children within
it:</p>
<pre>
<p style="width: 500px; padding: 5px; display: flexbox; flex-pack: distribute; flex-align: center;">
<button style="width: 200px;">Child 1<br>Another Line</button>
<button style="width: 100px;">Child 2</button>
<button style="width: 100px;">Child 3</button>
</p></pre>
<p>This will render approximately like the following:</p>
<p
style="border: thin solid black; background: white; width: 500px; padding: 5px; overflow: hidden;">
<button
style="float: left; width: 200px; height: 40px; margin-right: 50px;">Child
1<br>
Another Line</button> <button
style="float: left; width: 100px; height: 22px; margin-top: 9px;">Child
2</button> <button
style="float: right; width: 100px; height: 22px; margin-top: 9px;">Child
3</button></p>
</div>
<h3 id=display-flexbox><span class=secno>2.1. </span> New values for
‘<code class=property>display</code>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td>display
<tr>
<th>New value:
<td>flexbox | inline-flexbox
</table>
<p>You can declare that an element is a flexbox, and thus should use
flexbox layout for its contents, by setting the ‘<code
class=property>display</code>’ property on the element to the value
‘<a href="#flexbox"><code class=property>flexbox</code></a>’
or ‘<code class=property>inline-flexbox</code>’.
<p>The ‘<a href="#flexbox"><code class=css>flexbox</code></a>’
value makes the flexbox act like a block in other layout modes. The
‘<code class=css>inline-flexbox</code>’ value makes the
flexbox act like an inline-block in other layout modes.
<p>Flexboxes use a new layout algorithm, and so some properties that were
designed with the assumption of block layout don't make sense in a flexbox
context. In particular:
<ul>
<li>all of the ‘<code class=css>column-*</code>’ properties in
the Multicol module compute to their initial values on a flexbox
(‘<code class=property>break-before</code>’, ‘<code
class=property>break-inside</code>’, and ‘<code
class=property>break-after</code>’ are still valid on a flexbox).
<li>‘<code class=property>float</code>’ and ‘<code
class=property>clear</code>’ compute to their initial values on a
flexbox item
<li>‘<code class=property>vertical-align</code>’ has no effect
on a flexbox item
</ul>
<p>A flexbox creates a new flexbox formatting context for its contents.
This is similar to a block formatting context: floats must not intrude
into the flexbox, and the flexbox's margins do not collapse with the
margins of its contents. Additionally, all of the <a
href="#flexbox-item"><i>flexbox items</i></a> establish new block
formatting contexts for their contents.
<p class=issue>Figure out the right terms to use here.
<h3 id=flex-items><span class=secno>2.2. </span> Flexbox Items</h3>
<p>Flexbox layout algorithm operates on <a href="#flexbox-item"><i>flexbox
items</i></a>, which are boxes that satisfy at least one of the following
criteria:
<ol>
<li>Immediate block-level children of flexbox
<li>Atomic inline-level children of flexbox
<li>Contiguous run of non-replaced inline children, wrapped into an
anonymous block
</ol>
<div class=example>
<p>Examples of flexbox items:</p>
<pre>
<div style="display:flexbox">
<!-- flexbox item: block-level child -->
<div id="item1">block</div>
<!-- not a flexbox item, because it's out-of-flow -->
<div id="not-an-item1.5" style="position: absolute;">block</div>
<!-- flexbox item: block-level child -->
<div id="item2" style="display:table">table</div>
<!-- flexbox item: anonymous table wrapped around table-cell -->
<div id="item3" style="display:table-cell">table-cell</div>
<!-- flexbox item: anonymous block around inline content -->
anonymous item 4
<!-- flexbox item: block-level child -->
<div id="item5">block</div>
<!-- flexbox item: anonymous block around inline content -->
anonymous item 6.1
<span id="item6.1">
text 6.2
<div id="not-an-item6.3">block</div>
text 6.4
</span>
<!-- flexbox item: block-level replaced element -->
<iframe id="item7">
<!-- flexbox item: inline-level replaced element -->
<img id="item7" style="display:inline">
<!-- flexbox item: inline-level replaced element -->
<button id="item8">button</button>
<!-- flexbox item: inline-table -->
<div id="item9" style="display:inline-table">table</div>
</div></pre>
<p>Notice that block element "not-an-item6.3" is not a separate flexbox
item, because it is contained inside an inline element which is being
wrapped into an anonymous flex item. Similarly, the block element
"not-an-item1.5" is not a flexbox item, because it's absolutely
positioned and thus out of flow.</p>
</div>
<p>Similar to table cells, flexbox items respond specially to the
‘<code class=css>collapse</code>’ value of the ‘<code
class=property>visibility</code>’ property. When a flexbox item is
set to ‘<code class=css>visibility: collapse;</code>’, the
item does not generate a box at all (identical to setting ‘<code
class=css>display: none;</code>’).
<h4 id=abspos-flexbox-items><span class=secno>2.2.1. </span> Positioning
Absolutely Positioned Flexbox Items</h4>
<p>Absolutely positioned children of a flexbox are not <a
href="#flexbox-item"><i>flexbox items</i></a>, but their "static position"
(their 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 ‘<code
class=css>auto</code>’) responds somewhat to the flexbox's various
properties. The element's static position in the flexbox's <a
href="#cross-axis"><i>cross axis</i></a> is on the <a
href="#cross-start"><i>cross-start</i></a> edge of the flexbox's content
box. The static position in the flexbox's <a href="#main-axis"><i>main
axis</i></a> is slightly more complex to compute:
<p>First, find the element's <dfn id=hypothetical-neighbors>hypothetical
neighbors</dfn> by assuming that the element is a normal <a
href="#flexbox-item"><i>flexbox item</i></a> with ‘<code
class=css>flex-order:0</code>’, and reorder the flexbox's contents
as mandated by ‘<a href="#flex-order0"><code
class=property>flex-order</code></a>’. The <a
href="#flexbox-item"><i>flexbox items</i></a> immediately preceding and
following the element in the flexbox's direction (if any) are the
element's <a href="#hypothetical-neighbors"><i>hypothetical
neighbors</i></a>.
<p>If the element has two neighbors, its static position in the <a
href="#main-axis"><i>main axis</i></a> is exactly in the center of the
packing space between them when the flexbox is actually laid out. If the
element has only a preceding neighbor, its static position in the <a
href="#main-axis"><i>main axis</i></a> is flush with the <a
href="#main-end"><i>main-end</i></a> edge of the margin box of the
neighbor. If the element has only a following neighbor, its static
position in the <a href="#main-axis"><i>main axis</i></a> is flush with
the <a href="#main-start"><i>main-start</i></a> edge of the margin box of
the neighbor. Finally, if the element has no neighbors (the flexbox has no
in-flow children at all), the static position in the <a
href="#main-axis"><i>main axis</i></a> is based on the value of ‘<a
href="#flex-pack0"><code class=property>flex-pack</code></a>’: if
the value is ‘<a href="#flex-line-pack-start"><code
class=css>start</code></a>’ or ‘<code
class=css>distribute</code>’, it's flush with the <a
href="#main-start"><i>main-start</i></a> edge of the flexbox's content
box; if the value is ‘<a href="#flex-line-pack-end"><code
class=css>end</code></a>’, it's flush with the <a
href="#main-end"><i>main-end</i></a> edge of the flexbox's content box; if
the value is ‘<a href="#flex-line-pack-center"><code
class=css>center</code></a>’, it's centered within the flexbox's
content box.
<h2 id=ordering-orientation><span class=secno>3. </span> Ordering and
Orientation</h2>
<p>The first level of flexbox functionality is the ability to lay out a
flexbox's contents 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 using the ‘<code
class=property>float</code>’ property to lay out a horizontal
navigation bar (which then requires further effort with the ‘<code
class=property>clear</code>’ property or others to make the elements
interact nicely with the rest of the page). This functionality is exposed
through the ‘<a href="#flex-flow0"><code
class=property>flex-flow</code></a>’ and ‘<a
href="#flex-order0"><code class=property>flex-order</code></a>’
properties.
<h3 id=flex-flow><span class=secno>3.1. </span> Flexbox Flow Direction: the
‘<a href="#flex-flow0"><code
class=property>flex-flow</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=flex-flow0>flex-flow</dfn>
<tr>
<th>Values:
<td>[ row | row-reverse | column | column-reverse ] [ wrap |
wrap-reverse ]?
<tr>
<th>Initial:
<td>row
<tr>
<th>Applies To:
<td>flexboxes
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
<p>The ‘<a href="#flex-flow0"><code
class=property>flex-flow</code></a>’ property specifies how <a
href="#flexbox-item"><i>flexbox items</i></a> are placed in the flexbox.
The value consists of one or two keywords: the first sets the orientation
and direction of the flexbox's <a href="#main-axis"&
8096
gt;<i>main axis</i></a>,
which affects the direction that flexbox items are laid out in, and the
meaning of the ‘<a href="#flex-pack0"><code
class=property>flex-pack</code></a>’ properties; the second, if
specified, marks the flexbox as being multiline and sets the direction of
the <a href="#cross-axis"><i>cross axis</i></a>, which affects the
direction new lines are stacked in, and the meaning of the ‘<a
href="#flex-align0"><code class=property>flex-align</code></a>’ and
‘<a href="#flex-line-pack0"><code
class=property>flex-line-pack</code></a>’ properties.
<dl>
<dt><dfn id=flex-flow-row>row</dfn>
<dd>The flexbox's <a href="#main-axis"><i>main axis</i></a> has the same
orientation as the inline axis of the current writing mode (the 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
"start" and "end" directions, respectively, of the current writing mode.
<dt><dfn id=flex-flow-row-reverse>row-reverse</dfn>
<dd>Same as <a href="#flex-flow-row"><i>row</i></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>column</dfn>
<dd>The flexbox's <a href="#main-axis"><i>main axis</i></a> has the same
orientation as the block axis of the current writing mode (the 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
"before" and "after" directions, respectively, of the current writing
mode.
<dt><dfn id=flex-flow-column-reverse>column-reverse</dfn>
<dd>Same as <a href="#flex-flow-column"><i>column</i></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-wrap>wrap</dfn>
<dd>The flexbox is <a href="#multi-line"><i>multi-line</i></a>. The <a
href="#cross-start"><i>cross-start</i></a> direction is equivalent to
either the "start" or "before" direction of the current writing mode,
whichever is in the <i>cross-axis</i>, and the <a
href="#cross-end"><i>cross-end</i></a> direction is the opposite
direction of <a href="#cross-start"><i>cross-start</i></a>.
<dt><dfn id=flex-flow-wrap-reverse>wrap-reverse</dfn>
<dd>Same as <a href="#flex-flow-wrap"><i>wrap</i></a>, except the <a
href="#cross-start"><i>cross-start</i></a> and <a
href="#cross-end"><i>cross-end</i></a> directions are swapped.
</dl>
<p>If the second keyword is omitted, the flexbox is <a
href="#single-line"><i>single-line</i></a>, and the <a
href="#cross-start"><i>cross-start</i></a> and <a
href="#cross-end"><i>cross-end</i></a> directions are set as described
above for the ‘<a href="#flex-flow-wrap"><code
class=css>wrap</code></a>’ keyword.
<div class=example>
<p>Some examples of valid flows:</p>
<pre>
div { flex-flow: row; } /* Initial value. Main axis is inline,
no wrap. */
div { flex-flow: column wrap; } /* Main axis is block-direction and lines
wrap in the inline direction. For an
English page, the main axis is top-to-bottom
and lines wrap to the right. */
div { writing-mode: tb-rl; /* Main axis is block direction (right to left).
flex-flow: column wrap-reverse; } /* New lines wrap upwards. */</pre>
</div>
<p class=issue>Is there a good, shorter way to refer to the reversed
physical directions than the 8-character "-reverse" suffix?
<h3 id=flex-order><span class=secno>3.2. </span> Display Order: the
‘<a href="#flex-order0"><code
class=property>flex-order</code></a>’ property</h3>
<p><a href="#flexbox-item"><i>Flexbox items</i></a> are, by default,
displayed and laid out in the same order as they appear in the source
document. The ‘<a href="#flex-order0"><code
class=property>flex-order</code></a>’ property may be used to change
this ordering.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=flex-order0>flex-order</dfn>
<tr>
<th>Value:
<td><number>
<tr>
<th>Initial:
<td>0
<tr>
<th>Applies to:
<td><a href="#flexbox-item"><i>flexbox items</i></a>
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
<p>The ‘<a href="#flex-order0"><code
class=property>flex-order</code></a>’ property assigns <a
href="#flexbox-item"><i>flexbox items</i></a> to ordinal groups.
<p>Ordinal groups control the order in which <a
href="#flexbox-item"><i>flexbox items</i></a> appear. A flexbox will lay
out its content starting from the lowest numbered ordinal group and going
up. Items with the same ordinal group are laid out in the order they
appear in the source document.
<div class=example>
<p>This example shows how ordinal groups might be used.</p>
<pre>
div { display: flexbox; }
#item1, #item3 { flex-order: 1; }
#item4 { flex-order: 0; }
<div>
<button id="item1">One</button>
<button id="item2">Two</button>
<button id="item3">Three</button>
<button id="item4">Four</button>
</div></pre>
<p>Items 2 and 4 are both in ordinal group 0 (item 2 defaults to
‘<code class=css>0</code>’ because it doesn't specify one
explicitly). This is the lowest ordinal group, so they'll be displayed
first, and in document order, with Item 2 displayed before Item 4. The
remaining items are both in ordinal group 1, so the resulting display
order will be:</p>
<div style="border: medium solid green; display: inline-block;">
<button>Two</button> <button>Four</button> <button>One</button>
<button>Three</button></div>
</div>
<p class=issue>Add a realistic example of tab reordering.
<p class=issue>Add an example of reordering columns in a page.
<h2 id=flexibility><span class=secno>4. </span> Flexibility</h2>
<p>The defining aspect of flexbox layout is the ability to make the <a
href="#flexbox-item"><i>flexbox items</i></a> "flex", altering their width
or height to fill the available space. This is done by declaring a <dfn
id=flexible-length>flexible length</dfn> with the ‘<code
class=css>flex()</code>’ function, defined below.
<h3 id=flex-function><span class=secno>4.1. </span> The ‘<code
class=css>flex()</code>’ function</h3>
<p>The ‘<code class=css>flex()</code>’ function is used to
specify the parameters of a <dfn id=flexible-length0
title="flexible length|flexible lengths|flexible length's">flexible
length</dfn>: the <dfn id=positive-flexibility
title="positive flexibility">positive</dfn> and <dfn
id=negative-flexibility>negative flexibility</dfn>, and the <dfn
id=preferred-size>preferred size</dfn>. The syntax of the ‘<code
class=css>flex()</code>’ function is:
<pre
class=prod>flex( [ <pos-flex> <neg-flex>? ]? || <preferred-size>? )</pre>
<p><code><pos-flex></code> and <code><neg-flex></code> are
non-negative <code><numbers>s</code>, while
<code><preferred-size></code> is any value (other than another
‘<code class=css>flex()</code>’ function) that would be valid
in the ‘<code class=property>width</code>’ or ‘<code
class=property>height</code>’ property in which the function is
used, except that zero lengths must not omit their unit.
<p>The <code><pos-flex></code> component sets the length's <a
href="#positive-flexibility"><i>positive flexibility</i></a>; if omitted,
the <a href="#positive-flexibility"><i>positive flexibility</i></a>
defaults to ‘<code class=css>1</code>’. The
<code><neg-flex></code> component sets the length's <a
href="#negative-flexibility"><i>negative flexibility</i></a>; if omitted,
it defaults to ‘<code class=css>0</code>’. The
<code><preferred-size></code> component sets the length's <a
href="#preferred-size"><i>preferred size</i></a>; if omitted, it defaults
to ‘<code class=css>0px</code>’.
<p class=issue>Examples!
<h3 id=resolving-flexible-lengths><span class=secno>4.2. </span> Resolving
Flexible Lengths</h3>
<p class=note>Note: This section is non-normative.
<p><a href="#flexible-length0"><i>Flexible lengths</i></a> are resolved
into normal, inflexible lengths by figuring out how large all of the <a
href="#flexible-length0"><i>flexible lengths</i></a> in the flexbox
<em>want</em> to be, then either growing or shrinking that <a
href="#preferred-size"><i>preferred size</i></a> so that the <a
href="#flexbox-item"><i>flexbox items</i></a> exactly fill the flexbox,
neither overflowing nor leaving extra unfilled space.
<p><a href="#flexible-length0"><i>Flexible lengths</i></a> are resolved
into normal inflexible lengths based on their <a
href="#preferred-size"><i>preferred size</i></a>, their flexibility, and
the amount of free space in the flexbox. The exact algorithm is described
in <a href="#layout-algorithm">a later section of this spec</a>, but in
general, it works like this:
<ol>
<li>First, set all the <a href="#flexible-length0"><i>flexible
lengths</i></a> to their <a href="#preferred-size"><i>preferred
size</i></a>.
<li>Then, lay out the flexbox, and see if there is free space left, or if
the flexbox is overflowing.
<li>If there's free space, distribute it among the <a
href="#flexible-length0"><i>flexible lengths</i></a> in proportion to
their <a href="#positive-flexibility"><i>positive flexibility</i></a>. If
the flexbox is overflowing, shrink the <a
href="#flexible-length0"><i>flexible lengths</i></a> in proportion to
their <a href="#negative-flexibility"><i>negative flexibility</i></a>.
<li>If there's free space and any <a href="#flexible-length0"><i>flexible
lengths</i></a> are violating a max width or height constraint, change
them into the largest inflexible length that doesn't violate their
constraint and return to step 2. If the flexbox is overflowing and any <a
href="#flexible-length0"><i>flexible lengths</i></a> are violating a min
width or height constraint, change them into the smallest inflexible
length that doesn't violate their constraint and return to step 2.
<li>If there's free space and any <a href="#flexible-length0"><i>flexible
lengths</i></a> are violating a min width or height constraint, change
them into the smallest inflexible length that doesn't violate their
constraint and return to step 2. If the flexbox is overflowing and any <a
href="#flexible-length0"><i>flexible lengths</i></a> are violating a max
width or height constraint, change them into the largest inflexible
length that doesn't violate their constraint and return to step 2.
</ol>
<p class=issue>This is too much detail for a non-normative section. This is
living here only until I flesh out the layout algorithm section. Then this
can return to being a fairly simple explanation of what goes on.
<p>If a flexible length is used in a context where it is not allowed (for
example, on the ‘<code class=property>width</code>’ property
of an element that is not a <a href="#flexbox-item"><i>flexbox
item</i></a>), it represents its <a href="#preferred-size"><i>preferred
size</i></a>. Authors must not use flexible lengths in contexts where they
are not allowed.
<p class=issue>Examples!
<h2 id=alignment><span class=secno>5. </span> Alignment</h2>
<p>After a flexbox's contents have finished their flexing, they can be
aligned in both the <a href="#main-axis"><i>main axis</i></a> with
‘<a href="#flex-pack0"><code
class=property>flex-pack</code></a>’ and the <a
href="#cross-axis"><i>cross axis</i></a> with ‘<a
href="#flex-align0"><code class=property>flex-align</code></a>’.
These properties make many common types of alignment trivial, including
some things that were very difficult in CSS 2.1, like horizontal and
vertical centering.
<h3 id=flex-pack><span class=secno>5.1. </span> Main Axis Alignment: the
‘<a href="#flex-pack0"><code
class=property>flex-pack</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=flex-pack0>flex-pack</dfn>
<tr>
<th>Value:
<td>start | end | center | justify
<tr>
<th>Initial:
<td>start
<tr>
<th>Applies to:
<td>flexboxes
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
<p>The ‘<a href="#flex-pack0"><code
class=property>flex-pack</code></a>’ property aligns <a
href="#flexbox-item"><i>flexbox items</i></a> in the <a
href="#main-axis"><i>main axis</i></a> of the current line of the flexbox.
This is done <em title="">after</em> any flexible lengths have been
resolved. Typically it helps distribute extra free space leftover when
either all the <a href="#flexbox-item"><i>flexbox items</i></a> on a line
are inflexible, or are flexible but have reach their maximum size, but it
also exerts some control over the alignment of items when they overflow
the line.
<dl>
<dt><dfn id=flex-pack-start>start</dfn>
<dd><a href="#flexbox-item"><i>Flexbox items</i></a> are packed toward the
start of the line. The <a href="#main-start"><i>main-start</i></a> margin
edge of the first <a href="#flexbox-item"><i>flexbox item</i></a> on the
line is placed flush with the <a href="#main-start"><i>main-start</i></a>
edge of the line, and each subsequent <a href="#flexbox-item"><i>flexbox
item</i></a> is placed flush with the preceding item.
<dt><dfn id=flex-pack-end>end</dfn>
<dd><a href="#flexbox-item"><i>Flexbox items</i></a> are packed toward the
end of the line. The <a href="#main-end"><i>main-end</i></a> margin edge
of the last <a href="#flexbox-item"><i>flexbox item</i></a> is placed
flush with the <a href="#main-end"><i>main-end</i></a> edge of the line,
and each preceding <a href="#flexbox-item"><i>flexbox item</i></a> is
placed flush with the subsequent item.
<dt><dfn id=flex-pack-center>center</dfn>
<dd><a href="#flexbox-item"><i>Flexbox items</i></a> are packed toward the
center of the line. The <a href="#flexbox-item"><i>flexbox items</i></a>
23B3
div>
on the line are placed flush with each other and aligned in the center of
the line, with equal amounts of empty space between the <a
href="#main-start"><i>main-start</i></a> edge of the line and the first
item on the line and between the <a href="#main-end"><i>main-end</i></a>
edge of the line and the last item on the line. (If the leftover
free-space is negative, the <a href="#flexbox-item"><i>flexbox
items</i></a> will overflow equally in both directions.)
<dt><dfn id=flex-pack-justify>justify</dfn>
<dd><a href="#flexbox-item"><i>Flexbox items</i></a> are evenly
distributed in the line. If the leftover free-space is negative or there
is only a single <a href="#flexbox-item"><i>flexbox item</i></a> on the
line, this value is identical to ‘<a
href="#flex-line-pack-start"><code class=css>start</code></a>’.
Otherwise, the <a href="#main-start"><i>main-start</i></a> margin edge of
the first <a href="#flexbox-item"><i>flexbox item</i></a> on the line is
placed flush with the <a href="#main-start"><i>main-start</i></a> edge of
the line, the <a href="#main-end"><i>main-end</i></a> margin edge of the
last <a href="#flexbox-item"><i>flexbox item</i></a> on the line is
placed flush with the <a href="#main-end"><i>main-end</i></a> edge of the
line, and the remaining <a href="#flexbox-item"><i>flexbox items</i></a>
on the line are distributed so that the empty space between any two
adjacent items is the same.
</dl>
<div class=example>
<p class=issue>TODO: Examples showing the four values.</p>
</div>
<p class=note>A previous revision of this spec allowed margins to flex
directly, which allowed an effect similar to ‘<a
href="#flex-pack0"><code class=property>flex-pack</code></a>’. In
particular, it allowed an author to, for example, split a flexbox in half,
with some of the items pushed toward the start and the rest pushed toward
the end, by flexing exactly one margin. This sort of effect is no longer
possible without either using the ::before or ::after pseudoelements or
adding additional elements to the document, to act as an empty item that
can then flex. It's expected that we will develop something in the future