-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.src.html
More file actions
1504 lines (1342 loc) · 66.2 KB
/
Overview.src.html
File metadata and controls
1504 lines (1342 loc) · 66.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 PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html><head><title>CSS Flexible Box Layout Module</title>
<link rel="stylesheet" type="text/css" href="../default.css">
<style type="text/css">
p { margin: .5em 0; }
dd > p { text-indent: 0; }
a > b { font-weight: normal; color: #800; }
.auto-style1 {
font-weight: 800;
}
</style>
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED"> <!-- TODO: change before build -->
</head><body>
<div class="head">
<!--logo-->
<h1 id="head-box-flexible">CSS Flexible Box Layout Module</h1>
<h2 class="no-num no-toc" id="w3c-working">[LONGSTATUS], [DATE]</h2>
<dl>
<dt>This version:
<dd><!-- <a href="http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]/">http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]/</a></dd> -->
<a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</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>Tab Atkins Jr. <a href="mailto:jackalmage@gmail.com">jackalmage@gmail.com</a>
<dd>Alex Mogilevsky <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, Apple, <a href="mailto:hyatt@apple.com">hyatt@apple.com</a>
</dl>
<!--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.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<h2 class="no-num no-toc" id="table">Table of contents</h2>
<!--toc-->
<!-- ====================================================================== -->
<h2 id="overview">
Overview</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>
<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 'float' and 'columns', 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>
<p>Flexbox layout operates exclusively on immediate block-level children,
which are referred to as<dfn> flexbox item</dfn>s. Flexbox may directly
contain inline children or out of flow content, in which case flexbox item
fixup is performed, as described below.</p>
<p><em>Flexbox items </em>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.</p>
<p>If <dfn>multiline</dfn> option is enabled (by including one of 'wrap-' keywords in
'flex-flow' property), flexbox items flow in two dimensions, wrapping lines of
items similarly to wrapping lines of text. The two-dimensional flow can have
any combination of directions, matching current writing mode (logical),
independent of writing mode (physical) or mixed. </p>
<p>In flexbox, the term <dfn>main axis</dfn> refers to the primary
direction of flow of <i>flexbox item</i>s, the direction in which items are
added to layout in a single line flexbox, or in one line of multiline flexbox.
Main axis direction determines logical 'start' and 'end'.</p>
<p>The term <dfn>cross axis</dfn> refers to the direction orthogonal to main axis.
Direction of defines logical 'before' and 'after' for alignment and direction of
wrapping when wrapping is enabled.</p>
<p>Similar to other layout modes such as table layout, a flexbox acts like a
block when placed into other layout modes. Inline flexboxes can also be declared,
which act like inline-blocks.</p>
<div class="example">
<p>For example:</p>
<pre>
<p style="width: 400px; display: flexbox;">
<button style="width: 200px;">Child 1</button>
<button style="width: 100px;">Child 2</button>
</p>
</pre>
<p>In this example, the first button is 200 pixels wide and the second button is
100 pixels wide. As the flexbox is 400 pixels wide, there is extra space left over
which is placed after the two buttons but inside the flexbox. The placement of this
extra space may be modified using the various flex properties described in the next
sections. Neither the height of the buttons nor the height of the flexbox are specified,
so the height is computed intrinsically from the content. In this case, the buttons
will be the height needed to display the label and button border, and the flexbox will
also be this height plus any margins around the buttons.</p>
</div>
<p class="issue">this needs a picture</p>
<!-- ====================================================================== -->
<h2 id=display-flexbox>
New values for 'display' property</h2>
<table class="propdef">
<tbody>
<tr>
<th>Name:
<td>display
<tr>
<th>New value:
<td>flexbox | inline-flexbox
</tbody>
</table>
<p>You can declare that an element is a flexbox, and thus should use flexbox
layout, by setting the 'display' property on the element to the value
'flexbox' or 'inline-flexbox'.</p>
<p>Flexbox establishes a new block formatting context for its content.</p>
<!-- ====================================================================== -->
<h2 id=flex-items>
Flexbox Items</h2>
<p>Flexbox layout algorithm operates on <em>flexbox items.</em>
<p>Flexbox items are:<ol>
<li>Immediate block-level children of flexbox</li>
<li>Atomic inline-level children of flexbox</li>
<li>Contiguous run of non-replaced
inline children, wrapped into an anonymous block</li>
</ol>
<div class="example">
Examples of flexbox items
<pre>
<div style="display:flexbox">
<!-- flexbox item: block-level child -->
<div id="item1">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 -->
<img 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>
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.
</div>
<p>Out-of-flow elements like absolutely positioned elements
leave behind a 'placeholder' inline element in their original position in the
document <p class=issue>This needs to change. Placeholder is not fully hypothetical in this case,
that element or line is detectable in "flex-pack:justify". TODO: define the
"auto" positoin without a placeholder.
<p>Setting ''display:flexbox'' on an element forces it to 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:</p>
<ul>
<li>all of the 'column-*' properties in the Multicol module compute to their initial
values on a flexbox ('break-before', 'break-inside', and 'break-after' are still
valid on a flexbox).</li>
<li>'float' and 'clear' compute to their initial values on a flexbox item</li>
<li>'vertical-align' has no effect on a flexbox item</li>
</ul>
<p class="issue">It has been proposed that vertical-align property applies to flex items
(simliar to table cells). Decide if it makes sense, or if it should instead apply broader (to any blocks). </p>
<p>
A flexbox item creates a new BFC. The margins of a flexbox item
do not collapse with any other margin. Flexboxes "shrinkwrap" their contents
by default (when their 'width' or 'height' properties are ''auto''), similar
to tables or floats.</p>
<!-- ====================================================================== -->
<h2>
Flexbox Flow Direction: the 'flex-flow' property</h2>
<table class=propdef>
<tbody>
<tr>
<th style="width: 143px">Name:</th>
<td><dfn>flex-flow</dfn></td>
<tr>
<th style="width: 143px">Values:
<td>
<!-- TODO: remove PRE here if the default template has whitespace:pre -->
<pre style="margin:0; font:inherit"
>[ row | row-reverse | column | column-reverse ] || [ wrap | wrap-reverse ] |
[ horizontal | horizontal-reverse | horizontal-ltr| horizontal-rtl ] &&
[ wrap| wrap-reverse | wrap-down| wrap-up ]? |
[ vertical| vertical-reverse| vertical-ttb| vertical-btt ] &&
[ wrap | wrap-reverse | wrap-left | wrap-right ]?
</pre>
</td>
<tr>
<th style="width: 143px">Initial:
<td>row</td>
</tr>
<tr>
<th style="width: 143px">Applies To:
<td>flexboxes</td>
</tr>
<tr>
<th style="width: 143px">Inherited:
<td>no</td>
</tr>
<tr>
<th style="width: 143px">Computed Value:
<td>specified value</td>
</tr>
<tr>
<th style="width: 143px">Media:
<td>visual</td>
</tr>
</tbody>
</table>
<p>The 'flexbox-flow' property specifies how <i>flexbox item</i>s
are placed in the flexbox. The value of the property can consist of one or
two keywords describing direction of main axis and direction of wrapping. The
keyowrds have the following
meanings:</p>
<dl>
<dt><dfn id='flex-flow-horizontal'>horizontal</dfn></dt>
<dd><i>Flexbox item</i>s are placed horizontally.
In horizontal writing modes, items are added in inline direction of
current writing mode. In
vertical writing modes, items are added in block direction of current
writing mode.
</dd>
<dt><dfn id='flex-flow-horizontal-reverse'>horizontal-reverse</dfn></dt>
<dd><i>Flexbox item</i>s are placed horizontally. Items are added in
direction opposite to the direction defined by 'horizontal' value.</dd>
<dt><dfn id='flex-flow-horizontal-ltr'>horizontal-ltr</dfn></dt>
<dd><i>Flexbox item</i>s are placed horizontally, from left to right.</dd>
<dt><dfn id='flex-flow-horizontal-rtl'>horizontal-rtl</dfn></dt>
<dd><i>Flexbox item</i>s are placed horizontally, from right to left.</dd>
</dd>
<dt><dfn id='flex-flow-vertical'>vertical</dfn></dt>
<dd><i>Flexbox item</i>s are placed vertically.
In vertical writing modes, items are added in inline direction of
current writing mode. In
horizontal writing modes, items are added in block direction of current
writing mode.
</dd>
<dt><dfn id='flex-flow-vertical-reverse'>vertical-reverse</dfn></dt>
<dd><i>Flexbox item</i>s are placed vertically. Items are added in
direction opposite to the direction defined by 'vertical' value.</dd>
<dt><dfn id='flex-flow-vertical-ttb'>vertical-ttb</dfn></dt>
<dd><i>Flexbox item</i>s are placed vertically, from top to bottom.</dd>
<dt><dfn id='flex-flow-row-vertical-btt'>vertical-btt</dfn></dt>
<dd><i>Flexbox item</i>s are placed vertically, from bottom to top.</dd>
<dt><dfn id='flex-flow-row'>row</dfn></dt>
<dd><i>Flexbox item</i>s are placed in same orientation and direction as inline content in current writing mode.
</dd>
<dt><dfn id='flex-flow-row-reverse'>row-reverse</dfn></dt>
<dd><i>Flexbox item</i>s are placed in same orientation as inline content in current writing mode,
but in opposite direction.
</dd>
<dt><dfn id='flex-flow-column'>column</dfn></dt>
<dd><i>Flexbox item</i>s are placed in same orientation and direction as
block boxes in current writing mode.
</dd>
<dt><dfn id='flex-flow-column-reverse'>columns-reverse</dfn></dt>
<dd><i>Flexbox item</i>s are placed in same orientation as block boxes in current writing mode,
but in opposite direction.
</dd>
<dt><dfn id='flex-flow-wrap'>wrap</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
In horizontal writing modes, new lines are added in block direction.
In vertical writing modes, new lines are added in inline direction.
</dd>
<dt><dfn id='flex-flow-wrap-reverse'>wrap-reverse</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
New lines are added in direction opposite to the direction defined by 'wrap' value.
</dd>
<dt><dfn id='flex-flow-wrap-up'>wrap-up</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
New ines are added above.
</dd>
<dt><dfn id='flex-flow-wrap-right'>wrap-right</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
New ines are added to the right.
</dd>
<dt><dfn id='flex-flow-wrap-down'>wrap-down</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
New ines are added down.
</dd>
<dt><dfn id='flex-flow-wrap-left'>wrap-left</dfn></dt>
<dd>Flow of <i>flexbox item</i>s is wrapped into multiple lines as needed.
New ines are added tp the left.
</dd>
</dl>
<p>Not all combinaiton of main-axis direction and flow direction are allowed,
because some combinations don't make sense(for example "flex-flow: horizontal
wrap-right" is not possible).</p>
<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:horizontal-ltr wrap-down } /* main axis is horizontal, flow left-to-right,
wrap down */
div { flex-flow:wrap } /* main axis is inline direction(default),
wrap in block direction */
div { writing-mode:tb-rl; /* main axis is vertical top-to-bottom (as line direction),
flex-flow:vertical wrap-reverse } /* wrap direction is left-to-right (opposite to block direction) */
</pre>
</div>
<p class="auto-style1">For details on wrapping into multiple lines, see
<a href="#multiline">Multi-line flexbox</a></p>
<!-- ====================================================================== -->
<h2 id='flex-order'>
Display Order: the 'flex-order' property</h2>
<p><i>flexbox item</i>s are, by default, displayed and laid out in the same order
as they appear in the source document. The 'flex-order' property may be used
to change this ordering.</p>
<table class=propdef>
<tr>
<th>Name:
<td><dfn>flex-order</dfn>
<tr>
<th>Value:
<td><integer>
<tr>
<th>Initial:
<td>1
<tr>
<th>Applies to:
<td><i>flexbox item</i>s</td>
<tr>
<th>Inherited:
<td>no
<tr>
<th>Computed value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
<p><i>Flexbox item</i>s may be assigned to ordinal groups using the 'flex-order'
property. This property is an integer with an initial value of 1.</p>
<p>Ordinal groups control the order in which <i>flexbox item</i>s 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><code> div { display: flexbox; }
#item1 { flex-order: 2; }
#item3 { flex-order: 2; }
#item4 { flex-order: 1; }
<div>
<div id="item1">item1</div>
<div id="item2">item2</div>
<div id="item3">item3</div>
<div id="item4">item4</div>
</div></code></pre>
<p>The first ordinal group, 1, contains item2 and item4. As item2 does not
specify an ordinal group, it will default to 1. The elements will be displayed
in document order, so item2 will be displayed before item4. The second ordinal
group, 2, contains the remaining two items. The resulting display order will
be:</p>
<pre><code>item2 item4 item1 item3</code></pre>
</div>
<!-- ====================================================================== -->
<h2 id='flexibility'>
Flexibility</h2>
<p>The defining aspect of flexbox layout is the ability to make various lengths
of the <i>flexbox item</i>s flexible. The 'width', 'height', 'padding', and
'margin' properties of a <i>flexbox item</i> can all be made flexible. Paddings
and margins are made flexible by setting their value to ''auto'', while the
width and height of a box can be controlled more precisely with the ''flex()'' function, defined below.</p>
<div class=example>
<p class=issue>TODO: Examples!</p>
</div>
<h3 id='resolving-flexible-lengths'>
Resolving Flexible Lengths</h3>
<p>Flexbox layout resolves a <i>flexible length</i> into a definite length by first collecting
all the lengths, flexible or inflexible, that will share some space. For example,
for a horizontal flexbox, the lengths of the left and right margins, left and right
borders, left and right paddings, and widths of all <i>flexbox item</i>s share
the width of the flexbox itself. Conversely, each
<i title="flexbox item">flexbox item's</i> vertical margins, borders, padding,
and height individually share the height of the flexbox.</p>
<div class=figure>
<p class="caption issue">TODO: Diagram showing the relevant lengths
in each axis.</p>
</div>
<p>Flexbox layout then sums the <dfn>preflex size</dfn> of the lengths in each set. The
<i>preflex size</i> of an inflexible length is just the length itself. The
<i>preflex size</i> of a flexible length is its <i>preferred size</i>. If the
sum of all the <i title="preflex size">preflex sizes</i> is less than the
available width/height of the flexbox, then the difference is split up among all the
<i title="flexible length">flexible lengths</i> with <dfn>positive flexibility</dfn>,
with the space divvied up proportionally to the flexibility of each length. If
the sum is greater than the available width/height, then all the
<i title="flexible length">flexible lengths</i> with <dfn>negative flexibility</dfn>
shrink in proportion to their flexibility to try and make the sum equal the
available width/height.</p>
<p>The 'flex-pack' and 'flex-align' properties offer additional options for free-space distribution. The precise details of how free space is determined
and assigned to flexible lengths is detailed in a later chapter.</p>
<h3 id='flex-function'>
The ''flex()'' function</h3>
<p>The ''flex()'' function is used to specify the parameters of a
<i>flexible length</i>: the <i title="positive flexibility">positive</i>
and <i>negative flexibility</i>, and the <i>preferred size</i>. The syntax
of the ''flex()'' function is roughly (see following prose for a precise
description):</p>
<pre class=prod>flex( [ <i title="positive flexibility"><pos-flex></i> || <!--
--><i title="negative flexibility"><neg-flex></i> || <!--
--><i title="preferred size"><preferred-size></i> ] )</pre>
<p>Applicable to 'width' and 'height'</p>
<p class="note">In the future this may be applicable to margin and padding</p>
<dl>
<dt>If the ''flex()'' function contains a single value:</dt>
<dd>
<ul>
<li>If the value is a non-negative number, the <i>positive flexibility</i>
is set to that value, the <i>negative flexibility</i> is set to
''0'', and the <i>preferred size</i> is set to the initial value
of the property ('auto' for width and height).</li>
<li>Otherwise, if the value is a <length>, a <percentage>,
or a valid keyword, the <i>preferred size</i>
is set to that value, the <i>positive flexibility</i> and the <i>negative flexibility</i>
are set to initial value (zero)</li>
<li>Otherwise, the ''flex()'' function is invalid.</li>
</ul>
</dd>
<dt>If the ''flex()'' function contains two values:</dt>
<dd>
<ul>
<li>If both values are non-negative numbers, the <i>positive flexibility</i>
is set to the first value, the <i>negative flexibility</i> is set
to the second value, and the <i>preferred size</i> is set to its
initial value.</li>
<li>Otherwise, if one value is a non-negative number and the other
is a <length>, a <percentage>, or a valid keyword, the <i>positive flexibility</i> is set to the number, the
<i>negative flexibility</i> is set to ''0'', and the <i>preferred size</i>
is set to the other value.</li>
<li>Otherwise, the ''flex()'' function is invalid.</li>
</ul>
</dd>
<dt>If the ''flex()'' function contains three values:</dt>
<dd>
<ul>
<li>If the first two values are non-negative numbers and the third
value is ''0'', the <i>positive flexibility</i> is set to the first
value, the <i>negative flexibility</i> is set to the second value,
and the <i>preferred size</i> is set to ''0px''.</li>
<li>Otherwise, If two of the values are non-negative numbers, and the other
is a <length> (with a unit suffix), a <percentage>, or a
valid keyword, the <i>positive flexibility</i>
is set to the first number, the <i>negative flexibility</i> is set
to the second number, and the <i>preferred size</i> is set to the
other value.
</li>
<li>Otherwise, the ''flex()'' function is invalid.</li>
</ul>
</dl>
<dl>
<dt>If the ''flex()'' function contains less than one or more than three values:</dt>
<dd>
<ul>
<li>The "flex()" function is invalid</li>
</ul>
<p class="issue">Note change from previous draft: default/unspecified are
the initial values: still 'auto' for width/height, 0 if it is ever
applied to margings and padding; 0 for positive flexibility (was 1 in
previous draft).</p>
<p class='note'>Note that, while ''0'' <length> is normally allowed to
be specified without a unit suffix, in flex() function it is ambiguous, as
it is also an acceptable value for flexibility. All ambiguous cases are
resolved with preference to flexibility, thus unitless "0" can only be
applied to <em>preferred size </em>when three vaues are specified and
"0" is the last one.</p>
<p>User agents that allow non-zero
length values without unit suffix in "quirks mode" may also
accept a non-zero positive number as the <em>preferred size </em>
in pixels
when in "quirks mode" and when it is the third value in flex() function
with three values.</p>
<h3 id="flexible-margins">Flexible margins and paddings</h3>
<p>Paddings and margins are made flexible by setting their value to
'auto'. </p>
<p>When margin or padding size on a <em>flexbox item</em> is set to
'auto' in orientation of main axis, that margin or padding is
included in flexbox layout algorithm with flexibility of 1.</p>
<p>'Auto' margin can also be used for alignment along the <em>
cross-axis</em>, see <em><a href="#flex-align">'flex-align' property</a></em></p>
<p class="issue">
<a href="http://wiki.csswg.org/spec/css3-flexbox?&#issue-15">
(Issue 15)</a> Interpretation of 'auto' value for margins parallel to <i>
main axis </i>appears incomplete because flex() doen't apply, and
also margin/padding can't have min/max values. Flex() could be
allowed there, but it would be more complicated.</p>
<p class="issue">TODO: need solid use cases (and illustrations here)
for flexible margins and paddings.</p>
<!-- ====================================================================== -->
<h2 id='flex-pack'>The 'flex-pack' property</h2>
<table class=propdef>
<tr>
<th>Name:
<td><dfn>flex-pack</dfn>
<tr>
<th>Value:
<td>start | end | center | justify | inherit</td>
<tr>
<th>Initial:
<td>start
<tr>
<th>Applies to:
<td>flexboxes
<tr>
<th style="height: 20px">Inherited:
<td style="height: 20px">no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
<p>Between and around the margins of <i>flexbox item</i>s there are additional
flexible lengths, called <dfn>packing space</dfn>. Packing space can absorb
leftover free space in a flexbox if there aren't any other <i>flexible length</i>s,
or if all the <i>flexible length</i>s have reached their maximum size. The
'flex-pack' property defines the flexibility of these packing spaces:
<dl>
<dt><dfn id='flex-pack-start'>start</dfn></dt>
<dd><i>flexbox item</i>s are packed toward the start of the flexbox. The
last packing space (between the margin of the last flexbox item and the
edge of the flexbox) must absorb all leftover free space; all other packing
spaces must have a length of ''0''.</dd>
<dt><dfn id='flex-pack-end'>end</dfn></dt>
<dd><i>flexbox item</i>s are packed toward the end of the flexbox. The
first packing space (between the edge of the flexbox and the margin of the
first flexbox item) must absorb all leftover free space; all other packing
spaces must have a length of ''0''.</dd>
<dt><dfn id='flex-pack-center'>center</dfn></dt>
<dd><i>flexbox item</i>s are packed toward the center of the flexbox. The
first and last packing spaces must equally split all leftover free space;
all other packing spaces must have a length of ''0''.</dd>
<dt><dfn id='flex-pack-justify'>justify</dfn></dt>
<dd><i>flexbox item</i>s are evenly distributed through the flexbox. The
first and last packing spaces must have a length of ''0''; all other packing
spaces must equally split all leftover free space.</dd>
</dl>
<div class=figure>
<p class=caption><span class=issue>TODO: Provide a diagram showing packing
spaces.</span></p>
</div>
<div class=example>
<p class=issue>TODO: Examples showing the four values.</p>
</div>
<!-- ====================================================================== -->
<h2 id='flex-align'>The 'flex-align' property</h2>
<p>Sizing and positioning of <em>flexbox item</em>s along the <em>cross
axis</em> of flexbox is controlled by the 'flex-align' property.</p>
<table class=propdef>
<tr>
<th>Name:
<td><dfn id="propdef-flex-align">flex-align</dfn>
<tr>
<th style="height: 20px">Value:
<td style="height: 20px">before | after | middle | stretch | baseline
| inherit
<tr>
<th>Initial:
<td>stretch
<tr>
<th>Applies to:
<td>flexbox items
<tr>
<th style="height: 20px">Inherited:
<td style="height: 20px">no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>
</i>
<p>When the size of the containing box along<em> cross axis </em>is
larger than the size of a child, extra space will be available. The
'flex-align' property specifies how flexbox item is placed along the
<em>cross axis</em>, and where the extra space, if any, is
positioned. </p>
<p>The values of this property have the following meanings. See text for more specifics as to how children are
positioned. /p>
<dl>
<dt>before
<dd>The 'before' edge of the child box along<em> cross axis </em>is aligned with 'before' edge of the
flexbox content box. See text for explanation of how direction of <em>cross
axis</em> is determined.<dd>
<dt>after
<dd>The 'after' edge of the child box along<em> cross axis </em>is aligned with 'after' edge of the
flexbox content box. See text for explanation of how direction of <em>cross
axis</em> is determined.<dt>middle
<dd>Any extra space along the<em> cross axis </em>is divided evenly, with half placed
before the child
and the other half placed after the child.
<dt>baseline
<dd> If this child's inline axis is parallel to <em>main axis</em> of
the flexbox, the baseline of the child box is aligned with baselined of all
other child boxes that meet the same criteria. Baseline of each child box is
determined in the same way as when it is placed inline (as inline-block,
inline-table, etc.).
<dd>The children participating in baseline alignment, once
aligned on their baselines, should then be placed into the box
so that the child with the earliest extent margin has its
'before' margin edge flush with the 'before' edge of flexbox's
content area. If the flexbox does not have an '<code
class=property>auto</code>' height, overflow will always be on the
'after' edge.
<dd>If the child box <em>inline axis </em>is orthognal to
flexbox <em>main axis</em>, then <span >'baseline'</span> is
interpreted as <span >'center'</span>.
<dd>
<dt>stretch
<dd>The height of each child is adjusted to that of the containing block.
However, note the text below.
</dl>
<p>Direction of the <em>cross axis </em>is determined as follows:</p>
<p>In multi-line flexbox, <em>cross axis </em>points in the
direction of wrapping (the side where lines are added)</p>
<p>In single-line flexbox, the direction of <em>cross axis</em> is
determined by the computed value of writing mode of the flexbox
element.</p>
<ul>
<li> If flexbox's <em>main axis </em>is parallel to inline axis of
the writing mode, <em>cross axis</em> points in the direction of
block flow</li>
<li> If flexbox's <em>main axis </em>is parallel to block flow
axis of the writing mode, <em>cross axis</em> points in the
direction of inline flow</li>
</ul>
</ul>
<p>The following rules should be applied when determining the size of
child boxes along the<em> cross axis</em>. Exceptions to these rules
are noted under each of the possible values of '<code class=property><a
href="#propdef-flex-align">flex-align</a></code>' below.
<p>First, the <em>cross axis </em>size of content box of the flexbox
has to be calculated. If computed value of flexbox's width or height
(whichever is along the<em> cross axis</em>), that value is used. If
it is 'auto', the size is determined by flexbox items, as follows:<ol>
<li><em>Cross-axis s</em>izes of margin boxes of all children in
are checked and the biggest is selected.</li>
<li>If there are any children with baseline alignemnt, biggest
ascent (including its margin-before) and biggest descent
(including its margin-after) are found.</li>
<li>Flexbox's content box size is the size its biggest child or
the sum of the biggest ascent and biggest descent, whichever is
larger</li>
</ol>
<p>All normal flow children of boxes will attempt to satisfy the following
sizing equation when placed inside vertical boxes if and only if at least
one of the specified values is auto:
<p>'<code class=property>margin-left</code>' + '<code
class=property>border-left-width</code>' + '<code
class=property>padding-left</code>' + '<code
class=property>width</code>' + '<code
class=property>padding-right</code>' + '<code
class=property>border-right-width</code>' + '<code
class=property>margin-right</code>' = width of containing box
<p>and a similar equation for height when placed inside horizontal boxes:
<p>'<code class=property>margin-top</code>' + '<code
class=property>border-top-width</code>' + '<code
class=property>padding-top</code>' + '<code
class=property>height</code>' + '<code
class=property>padding-bottom</code>' + '<code
class=property>border-bottom-width</code>' + '<code
class=property>margin-bottom</code>' = height of containing box
<p>If all the values in the equation are specified (i.e., if there are no
auto values), then the equation above does not apply, and the specified
values should be used. If applying the equation results in a negative
value for width/height, then that value is set to 0, and those values
should be used.
<p>If the value of <span class=property>'<code class=property><a
href="#propdef-flex-align">flex-align</a></code>'</span> is <span
class=property>'stretch'</span>, then elements obey the sizing rules
specified above. This is the default value. If both width/height and one or
both margin values are '<code class=property>auto</code>', the '<code class=property>auto</code>'
margins are set to 0 and the equation is used to find a value for
width/height. Otherwise, if both margins are '<code class=property>auto</code>', then the
equation is solved under the additional constraint that the two margins
must get the same value. If neither the width/height or either margin is
auto, then the extra space is positioned as if flex-align was 'before'.
<p>If the value of <span class=property>'<code class=property><a
href="#propdef-flex-align">flex-align</a></code>'</span> is before, middle,
baseline or after, and a value of '<code
class=property>auto</code>' is specified for width/height, then the
intrinsic size (or shrink to fit size) of the element should be used. If
one margin has the value of auto, then the equations above should be used.
If both margins have a value of auto then the above equations should be
used, with the space being divided evenly between the two margins. These
rules are similar to the rules for replaced elements inside blocks.
<p>If the above would cause the width or height to greater than the
computed maximum width or height, then the width or height is set to the
maximum width or height, and the auto margins increased by the extra
amount left over. If both margins are auto, they should both be increased
by the same amount. If neither margin is auto, the extra space is placed
as necessary depending on the flex-align value.
<p>Once the sizes are computed, the margin boxes of the elements should be
aligned at the before, middle, baseline or after edge of the box.
<div class=example>
<p>A vertical flexbox can be used to emulate the functionality of HTML's
''<center>'' element:</p>
<pre><div>
<span>foo foo foo foo</span>
<span>bar bar<br>bar bar</span>
<span>foo foo foo foo foo foo foo foo foo foo foo foo</span>
</div>
<style>
div {
display: flexbox;
flex-direction: tb;
width: 200px;
}
span {/* /* */ */
margin: 0 auto;
}
</style>
</pre>
<p><img alt="" src="images/basic-vertical-flexbox.png"></p>
</div>
<p class="issue">
TODO: examples, with pictures
<p class="issue">TODO: alignment rules should be compatible with css3-grid-layout,
if possible</p>
<!-- ====================================================================== -->
<h2 id=multiline>Multi-line flexbox</h2>
<p>If no 'wrap-' keyword is included in 'flex-flow', flexbox lays out its
items in a single row or column; any items that don't fit will simply be considered
overflow.
<p>Adding any of the 'wrap-' keywords to 'flex-flow' enables multi-line mode.
Then flexbox is allowed to
expand to multiple lines (that is, multiple rows or columns) in order to
accommodate all of its items. Flexbox must attempt to fit its items
on as few lines as possible by shrinking all items down to their
minimum widths or heights if necessary.
<p>If the items still do not fit on a line after
being reduced to their minimum widths or heights, then items are moved one by one
onto a new line, until the items remaining on the previous line fit.
This process can repeat to an arbitrary number of lines. If a line
contains only a single item that doesn't fit, then the item should
stay on that line and overflow out of the box. The later lines are placed
according to wrap direction specified in 'flex-flow'.
<p>The cross-axis size of a line is the cross-axis size of the largest item
in that line. No additional space appears between the lines apart from the
margins on the largest items in each line. For calculating the cross-axis size
of a line, margins with a computed value of auto should be treated as
having a value of 0.
<p>Once the number of lines has been determined, items with non-zero flexibility
stretch as necessary in an attempt to fill
the remaining space on the lines. Each line computes flexes independently,
so only elements on that line are considered when evaluating flex.
The packing of elements in a line, as specified by the
flex-pack property, is also computed independently for each line.
<div class=example>
<p>This example shows four buttons that do not fit horizontally.</p>
<pre> #div1 {
display: flexbox;
flex-flow: wrap;
width: 300px;
}
button {
width: flex(80px 1.0);
}
<div id="div1">
<button id="button1">Elephant</button>
<button id="button2">Tiger</button>
<button id="button3">Antelope</button>
<button id="button4">Wildebeest</button>
</div>
</pre>
<p>The buttons are shrunk to their minimum widths, in this case 80 pixels.
This will allow the first three buttons to
fit in 240 pixels with 60 pixels left over of remaining space. Because
the box-lines property has a specified value of multiple, the fourth
button may be moved onto a second line.</p>
<p>Flexibility is applied to each element, separately for each line. The
first line has 60 pixels of remaining space, so each of the three buttons
on that line will receive 20 pixels of extra width. The remaining button
on a line of its own will stretch to the entire width of the containing
box, or 300 pixels.</p>
<div style="width:300px; border:medium solid green">
<button style="width:100px">Elephant</button
><button style="width:100px">Tiger</button
><button style="width:100px">Antelope</button
><button style="width:300px">Wildebeest</button></div>
<p>If the box was resized, the buttons may rearrange onto different lines
as necessary. If the style rules in the example above were changed to the
following:</p>
<pre> #div1 {
display: flexbox;
flex-flow: wrap;
flex-pack: center;
width: 300px;
}
button {
width: flex(80px 1.0);
max-width: 90px;
}
</pre>
<p>Now, each of the buttons will only stretch to include an additional 10
pixels of width, as the maximum width of 90 pixels is only 10 pixels
larger than the minimum intrinsic width of the buttons. The remaining 30
pixels of space left over is divided up and placed inside the box outside
of the buttons, as the value of box-pack is center. The fourth button
will also appear at 90 pixels wide, centered within the box.</p>
<div style="width:300px; border:medium solid green; text-align:center;">
<button style="width:90px">Elephant</button
><button style="width:90px">Tiger</button
><button style="width:90px">Antelope</button
><button style="width:90px">Wildebeest</button></div>
</div>
<!-- ====================================================================== -->
<h3 id=flex-line-pack>'flex-line-pack' property</h3>
<table class=propdef>
<tr>
<th>Name:
<td><dfn id="propdef-flex-line-pack">flex-line-pack</dfn>
<tr>
<th>Value:
<td>before | after | middle | distribute | inherit</td>
<tr>
<th>Initial:
<td>before
<tr>
<th>Applies to:
<td>flexboxes
<tr>
<th style="height: 20px">Inherited:
<td style="height: 20px">no
<tr>
<th>Computed Value:
<td>specified value
<tr>
<th>Media:
<td>visual
</table>