forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.old.src.html
More file actions
1071 lines (893 loc) · 47.6 KB
/
Overview.old.src.html
File metadata and controls
1071 lines (893 loc) · 47.6 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>Flexible Box Layout Module</title>
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
<link rel="stylesheet" type="text/css" href="../default.css">
</head><body>
<div class="head">
<h1 id="head-box-flexible">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>Editors:
<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"><a name="abstract">Abstract</a></h2>
<p>The draft describes a CSS box model optimized for interface design.
It provides an additional layout system alongside the ones already in
CSS. [[!CSS21]] In this new box 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. This
model is based on the box model in the XUL user-interface language
used for the user interface of many Mozilla-based applications
(such as Firefox).</p>
<h2 class="no-num no-toc" id="table"><a name="contents">Table of
contents</a></h2>
<!--toc-->
<hr>
<h2 id="overview">Overview</h2>
<p>
Flexible boxes lay out their children using a constraint-based system that
supports both relative flexible sizing and intrinsic sizing. Elements within
a box may be intrinsically sized yet have their size increased if additional
space is available in the container or have their size reduced if less space
is available. In addition, the position and order of elements within a box
may be modified.
</p><p>
In CSS, flexible boxes (often referred to only as boxes in this
specification) may be created by setting the <span class="property">'display'</span>
property. A block-level box can be specified with a value of <span class="css">'box'</span>
and an inline box can be specified using a value of <span class="css">inline-box</span>.
</p><p>
A block-level box placed inside a block level element is positioned and sized as if
it were any other block. An inline-level box placed inside another element is
positioned and sized like an inline-block.
</p><p>
Inline children of a flexible box are wrapped in anonymous blocks. All other children
are block-level. Elements within boxes are sized intrinsically. This means that the size is
determined by the size needed for its content, or, in the case of replaced elements,
the size of the replaced element. The intrinsic size of non-replaced elements may be affected
by widths and heights specified on the descendants. When determining the intrinsic size of an
element, the calculation is done without adding any line breaks, except those necessary
(e.g. for content with a white-space of 'pre').
</p><p>
Children of boxes may specify their width and height using the
<span class="property">'width'</span> and <span class="property">'height'</span>
properties. The width and height of replaced elements is computed as with
replaced elements in inline contexts. Otherwise, if the width is set to 'auto', then the
used value is the intrinsic size, which may be calculated using a shrink-to-fit algorithm,
as with inline-block elements, i.e., it will be given the minimum amount of space required
to lay out the element without unnecessary line breaks. Similarly, if the height is set to
'auto', then the used value in a similar manner.
</p><p>
An unnested box placed inside an enclosing block will obey all the
usual sizing rules of the block. For example, setting the width of an unnested box to
100% ensures that the box is the maximum width permitted by the enclosing block
(ignoring any margins, border and padding on that box).
</p><p>
The difference between boxes and blocks is in how the children of the
element are laid out. Children of boxes are all block-level (inline-level
contents get wrapped in anonymous blocks, as described in the section on
<a href="http://damowmow.com/temp/csswg/old/ui/inlinesAndBlocks">inlines and blocks</a>).
These blocks then get stacked in the direction specified by the
<span class="property">'box-orient'</span> and
<span class="property">'box-direction'</span> properties,
and order specified by the
<span class="property">'box-ordinal-group'</span> property.
They are aligned within the box according to the
<span class="property">'box-align'</span> property. The boxes may then flex
or be distributed as specified by the <span class="property">'box-flex'</span>,
<span class="property">'box-flex-group'</span>,
<span class="property">'box-pack'</span> and
<span class="property">'box-lines'</span> properties.
</p><p>
The <span class="property">'float'</span> and
<span class="property">'clear'</span> properties do not apply to
children of box elements, so the used value for these properties
is 'none'. These properties do apply to the box itself if it is
not a child of another box.
</p>
<div class="example">
<p>
For example:
</p>
<pre>
<p style="width: 400px;">
<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 box is 400 pixels wide, there is extra space left over
which is placed after the two buttons but inside the box. The placement of this
extra space may be modified using the various box properties described in the next
sections. Neither the height of the buttons nor the height of the box 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 box will
also be this height plus any margins around the buttons.
</p>
</div>
<p>
Elements within a box may use the <span class="property">'overflow'</span> property
to control whether a scrolling mechanism appears when the children of a box overflow.
A scrolling mechanism may be displayed when flexible elements are reduced below their minimum
intrinsic size when the overflow property is set to <span class="css">auto</span>
or <span class="css">scroll</span>.
If overflow is <span class="css">hidden</span>, the element will be clipped instead. <em>Note
that the initial value is <span class="css">visible</span>, which is
typically not the preferred effect in user interfaces.</em>
</p>
<h2 id="orientation">Orientation</h2>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-orient">box-orient</dfn>
<tr valign=baseline><td><em>Value:</em> <td>horizontal | vertical | inline-axis | block-axis | <span class="default">inherit</span>
<tr valign=baseline><td><em>Initial:</em> <td>inline-axis
<tr valign=baseline><td><em>Applies to:</em> <td>box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>
A box may lay out its children either horizontally or vertically.
</p>
<dl>
<dt>horizontal
</dt><dd>The box displays its children from left to right in a horizontal line.
</dd><dt>vertical
</dt><dd>The box displays its children from stacked from top to bottom vertically.
</dd><dt>inline-axis
</dt><dd>The box displays its children along the inline axis.
</dd><dt>block-axis
</dt><dd>The box displays its children along the block axis.
</dd></dl>
<p>
The inline and block axes are the writing-mode dependent keywords which,
in English, map to horizontal and vertical respectively.
</p>
<h2 id="displayorder">Display order</h2>
<p>
Children within a horizontally oriented box are, by default, displayed from
left to right in the same order as they appear in the source document. Children
within a vertically oriented box are displayed top to bottom in the same
order. The box-direction and box-ordinal-group properties may be used to
change this ordering.
</p>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-direction">box-direction</dfn>
<tr valign=baseline><td><em>Value:</em> <td>normal | reverse | <span class="default">inherit</span>
<tr valign=baseline><td><em>Initial:</em> <td>normal
<tr valign=baseline><td><em>Applies to:</em> <td>box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p> The <span class="property">'box-direction'</span>
property specifies the direction in which children of a box are displayed.
</p><dl>
<dt>normal
</dt><dd>A box with a computed value of horizontal for box-orient displays its
children from left to right. A box with a computed value of vertical displays
its children from top to bottom.
</dd><dt>reverse
</dt><dd>A box with a computed value of horizontal for box-orient displays its
children from right to left. A box with a computed value of vertical displays
its children from bottom to top.
</dd></dl>
<p>
If the computed value for the box's 'direction' property is 'normal', a
child's left edge is placed next to the right edge of the previous child, or
the left edge of the box for the first child. If the computed value for the box's
'direction' property is 'reverse', a child's right edge is placed next to the left
edge of the previous child, or the right edge of the box for the first child.
</p>
<p>
When the computed value for the overflow property is 'visible', 'scroll' or 'auto',
the content may overflow the container. If the computed value for direction is normal,
the content will overflow over the right or bottom side. If the computed value for
direction is reverse, the content will overflow over the left or top side.
</p>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-ordinal-group">box-ordinal-group</dfn>
<tr valign=baseline><td><em>Value:</em> <td><integer>
<tr valign=baseline><td><em>Initial:</em> <td>1
<tr valign=baseline><td><em>Applies to:</em> <td>children of box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>The children of a box element may be assigned to <dfn id="ordinal0">ordinal
groups</dfn> using the <span class="property">'box-ordinal-group'</span>
property. This property is a natural number value with an initial value is 1.
</p><p>Ordinal groups can be used in conjunction with the 'box-direction'
property to control the order in which the direct children of a box appear.
When the computed box-direction is normal, a box will display its elements
starting from the lowest numbered ordinal group and ensure that those elements
appear to the left (for horizontal boxes) or at the top (for vertical boxes)
of the container. Elements with the same ordinal group are flowed in the order
they appear in the source document tree. In the reverse direction, the
ordinal groups are examined in the same order, except the elements appear
reversed.
<div class="example">
<p>
This example shows how ordinal groups might be used.
</p>
<pre>
#div1 { display: box; }
#span1 { box-ordinal-group: 2; }
#span3 { box-ordinal-group: 2; }
#span4 { box-ordinal-group: 1; }
<div id="div1">
<span id="span1" >Sentence One</span>
<span id="span2" >Sentence Two</span>
<span id="span3" >Sentence Three</span>
<span id="span4" >Sentence Four</span>
</div>
</pre>
<p>
The first ordinal group, 1, contains span2 and span4. As span2 does not specify an
ordinal group, it will default to 1. The elements will be displayed in document order,
so span2 will be displayed before span4. The second ordinal group, 2, contains the
remaining two spans. The resulting display order will be:
</p>
<pre>
span2 span4 span1 span3
</pre>
</div>
<p>Elements within a box can use the <span class="property">'visibility'</span>
property to render themselves invisible. Boxes behave like tables in that the value
<span class="css">collapsed</span> can be used to specify that an element within a
box should not take up any space at all. The computed width and height of a collapsed
element are both 0, and the element is not considered when calculating flexibility.
Other non-collapsed flexible elements may expand as needed to fill in any space left
open by a collapsed element.
<!--
<h2 id="boxsizing">Box sizing</h2>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-sizing">box-sizing</dfn>
<tr valign=baseline><td><em>Value:</em> <td>content-box | padding-box | border-box | margin-box
<tr valign=baseline><td><em>Initial:</em> <td>1
<tr valign=baseline><td><em>Applies to:</em> <td>box and block elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual</a>
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>The <span class="property">'box-sizing'</span>
property determines how the <span class="property">'height'</span> and
<span class="property">'width'</span> properties should be interpreted.
</p><dl>
<dt>content-box
</dt><dd>This is the behavior of width and height as specified by CSS2. The
specified width and height apply to the width and height respectively of
the content box of the element. The padding and border of the element are
drawn outside the specified width and height.
</dd><dt>padding-box
</dt><dd>The specified width and height of this element determine the padding
box of the element. That is, any padding specified on the element is
drawn inside this specified width and height. The content width
and height is computed by subtracting the padding of the respective
sides from the specified width and height. The padding-box size is the
dimension used for the containing block of absolutely positioned blocks.
</dd><dt>border-box
</dt><dd>The specified width and height of this element determine the border
box of the element. That is, any padding or border specified on the
element is laid out and drawn inside this specified width and height. The
content width and height is computed by subtracting the border and
padding of the respective sides from the specified width and
height. This is the behavior of width and height as commonly implemented
by legacy HTML user agents for replaced elements and input elements.
</dd><dt>margin-box
</dt><dd>The specified width and height of this element determine the margin
box of the element. That is, any margin, padding or border specified on
the element is laid out and drawn inside this specified width and height.
The content width and height is computed by subtracting the margin,
border and padding of the respective sides from the specified
width and height. When margins collapse, the height (or width, for
horizontal block layout) is calculated before applying any collapsing
algorithms.
</dd></dl>
<p>Note that despite the name of the property, <span class="property">'box-sizing'</span> applies to block and
table-level elements as well as boxes.
-->
</p><h2 id="alignment">Alignment</h2>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-align">box-align</dfn>
<tr valign=baseline><td><em>Value:</em> <td>start | end | center | baseline | <span class="default">stretch</span>
<tr valign=baseline><td><em>Initial:</em> <td>stretch
<tr valign=baseline><td><em>Applies to:</em> <td>box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>
When the size of the containing box is larger than the size of a child,
extra space will be available.
The <span class="property">'box-align'</span>
property specifies how a box's children are placed and aligned along the direction
perpendicular to the box orientation, and where the extra space, if any, is
positioned. For horizontal orientation, it
specifies how the children are positioned vertically. For vertical
orientation, it specifies how the children are positioned horizontally.
</p><p>The amount of extra space may be different for each child. For example, if
the containing box has a height of 200 pixels, and it contains two children at
100 and 150 pixels respectively, there will be 100 pixels of extra space for the
first child and 50 pixels of space for the second child.
</p><p>The following values are valid for the box-align property, but see the
text afterward for more specifics as to how children are positioned.
<dl>
<dt>start
</dt><dd>For normal direction boxes, the top edge of each child is placed
along the top of the box. Extra space is placed below the element. For reverse
direction boxes, the bottom edge of each child is placed
along the bottom of the box. Extra space is placed above the element.
</dd><dt>end
</dt><dd>For normal direction boxes, the bottom edge of each child is placed
along the bottom of the box. Extra space is placed above the element. For reverse
direction boxes, the top edge of each child is placed
along the top of the box. Extra space is placed below the element.
</dd><dt>center
</dt><dd>Any extra space is divided evenly, with half placed above the child
and the other half placed after the child.
</dd><dt>baseline
</dt><dd>If this box orientation is inline-axis or horizontal, all children are
placed with their baselines aligned, and extra space
placed before or after as necessary. For block flows, the baseline of the first
non-empty line box located within the element is used. For tables, the baseline
of the first cell is used. The children, once aligned on their baselines, should
then be placed into the box so that the child with the earliest extent margin has
its top margin edge (or bottom margin edge for reverse direction boxes) flush with
the top (or bottom) edge of the box's content area. If the box does not have an
'auto' height, overflow will always be on the bottom (or top for reverse direction
boxes) edge. If the box orientation is block-axis or vertical, then
<span class="css">baseline</span> is interpreted as <span class="css">center</span>.
</dd><dt>stretch
</dt><dd>The height of each child is adjusted to that of the containing block. However,
note the text below.
</dd></dl>
<p>The following rules should be applied when determining the size of
children inside boxes in the dimension opposite to the orientation of the
box. Exceptions to these rules are noted under each of the possible values
of 'box-align' below.
</p><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><p>'margin-left' + 'border-left-width' + 'padding-left' + 'width' +
'padding-right' + 'border-right-width' + 'margin-right' = width of
containing box
</p><p>and a similar equation for height when placed inside horizontal boxes:
</p><p>'margin-top' + 'border-top-width' + 'padding-top' + 'height' +
'padding-bottom' + 'border-bottom-width' + 'margin-bottom' = height of
containing box
</p><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><p>If the value of <span class="property">'box-align'</span>
is <span class="css">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 'auto', the 'auto' margins are set to 0 and the equation
is used to find a value for width/height. Otherwise, if both margins are
'auto', 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 box-align
was start.
</p><p>If the value of <span class="property">'box-align'</span>
is start, center, baseline, or
end, and a value of 'auto' 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><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 box-align
value.
</p><p>Once the sizes are computed, the margin boxes of the elements should be
aligned at the start, center, baseline, or end of the box. For horizontal
boxes, this typically means the top, center, baseline or bottom of the
box. For vertical boxes, the start and end alignments depend upon the
direction. For LTR, the elements would be aligned at the left side of the
box for start and the right side for end. For RTL, the elements would be
aligned at the right of the box for start and the left side for end.
</p><h2 id="flex">Flexibility</h2>
<p>Each element directly within a box may be made either
<dfn id="flexible">flexible</dfn> or <dfn id="inflexible">inflexible</dfn>.
Flexible elements may grow when the containing box has extra space available
after the size of all of its children have been computed, and shrink if the
size would cause the containing box to overflow, yet the preferred width of
the flexible element is larger than its minimum width. Inflexible elements do not
change in size, even when there is extra space left over in the box.
</p><p>
The flexibility only affects the size in the axis along the box's orientation.
(e.g. the flexibility only affects the width in a horizontal box, and only
the height in a vertical box.)
</p>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-flex">box-flex</dfn>
<tr valign=baseline><td><em>Value:</em> <td><number>
<tr valign=baseline><td><em>Initial:</em> <td>0.0
<tr valign=baseline><td><em>Applies to:</em> <td>in-flow children of box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-flex-group">box-flex-group</dfn>
<tr valign=baseline><td><em>Value:</em> <td><integer>
<tr valign=baseline><td><em>Initial:</em> <td>1
<tr valign=baseline><td><em>Applies to:</em> <td>in-flow children of box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>An element is flexible when the <span class="property">box-flex</span>
property is specified. The <span class="property">box-flex</span>
property is a floating point value representing the flexibility of the element. Its
initial value is 0, which indicates that the element is inflexible. Elements
that are flexible can shrink or grow as the box shrinks and grows.
Whenever there is extra space left over in a box, the flexible elements are
expanded to fill that space. All flex is relative. For example, a child
with a box-flex of 2 is twice as flexible as a child with a box-flex of 1. A negative
value for box-flex is not allowed.
<p>Flexible elements can be assigned to <dfn id="flex-groups0">flex
groups</dfn> using the <span class="property">'box-flex-group'</span> property. This property
is a natural number value (the first flex group is 1 and higher values
are later flex groups). The initial value is 1.
</p><p>
In a horizontally oriented box, the preferred width of each child is computed. If
the width of the margin box of each child is equal to the width of the containing block,
then there is no extra space available, so the preferred widths are used for each child.
If the width of the margin box adds up
to a value smaller than the width of the containing block, then extra space is
available. This extra space is divided up among the flexible children, as described
below. If the width of the margin box adds up to a value larger than the width of the
containing block, then the flexible children shrink as much as necessary to prevent
overflow.
</p><p>
Flexibility only applies to elements in normal flow. As absolute and fixed positioned
elements are not in flow, any flexibility or flexgroup specified on them is ignored.
In addition, as the <span class="property">'float'</span> property does not apply to
children of flexible boxes, they are considered part of normal flow and flexibility
does apply.
</p><p>
When dividing up extra space, first take all elements within the first flex group.
Each element within that group should be given extra width based on the ratio of
that element's flexibility compared to the flexibility of other elements within
the same flex group.
</p>
<p>
However, if the preferred width of the element plus the extra width allotted to it
is larger than the maximum width of the element, then the width is set to that
maximum width, and any remaining extra width beyond that is divided up among the
other children.
</p>
<div class="example">
<p>
In this example there is 60 pixels of extra space available in the containing box.
</p>
<pre>
#div1 { display: box; width: 300px; }
#button1 { box-flex: 1.0; width: 100px; }
#button2 { box-flex: 2.0; width: 140px; }
<div id="div1">
<button id="button1">Hello</button>
<button id="button2">Goodbye</button>
</div>
</pre>
<p>
As both child buttons are flexible, the extra space will be divided up between them.
The first child button has a flexibility of 1.0 and the second child button has a
flexibility of 2.0. The first button will receive 20 pixels of extra width and the second
button will receive 40 pixels of extra width, maintaining the same ratio of extra width
to flexibility values. This extra width is added to the preferred size of the element.
</p>
<p>
However, if the second button had a maximum width of 150 pixels, it
could only grow by 10 pixels before hitting this maximum size, so the remaining
30 pixels would instead be given to the first element, breaking the flexibility ratio.
</p>
</div>
<p>
More specifically, the percentage of extra space that an element may receive is calculated
as follows:
</p><p>'box-flex of child' / 'total of box-flex values of child and all siblings'
</p><p>
If the width of all flexible children within the group has been increased to their
maximum widths, the process repeats for the children within the next flex group,
using any space left over from the previous flex group. Once there are no more flex groups,
and there is still space remaining, the extra space is divided within the containing
box according to the box-pack property.
</p><p>
If the box would overflow after the preferred width of the children have been computed,
then width is removed from flexible elements in a manner similar to that used when adding
extra space. Each flex group is examined in turn and space is removed according to
the ratio of the flexibility of each element. Elements do not shrink below their
minimum widths.
</p><p>
If all children have been shrunk to their minimum sizes, then the box overflows,
although if the box-lines property is set to multiple, the box may be able to move
elements to additional lines to prevent this.
</p><p>
For vertically oriented boxes, the algorithm as described above is similar except
using the height instead of the width.
</p><p>
When a child box of a horizontally oriented box contains an inline element, it is
likely that shrinking the width of the element due to flexibility may cause the
inline element to grow in height, as the text within it may need to wrap to
additional lines.
</p>
<div class="example">
<p>
Examples:
</p>
<pre>
#div1 { display: box; box-orient: vertical; height: 200px }
<div id="div1">
<button>Cat</button>
<button style="box-flex: 1">Piranha</button>
<button>Antidisestablishmentarianism</button>
</div>
</pre>
<p>
In the example above, the box is 200 pixels tall and is more than
enough room for the three buttons. Because the first and third buttons
are inflexible, they remain the same size, which is their intrinsic size.
The second button is specified as being flexible, and because it is the only
flexible element in the box, it receives all of the extra space.
</p>
<pre>
<div style="display: box; box-orient: vertical;">
<button style="box-flex: 1; height: 1000px;">
Cat
</button>
</div>
</pre>
<p>
In this example, if the height of the box is reduced, for instance, because
the user resized the containing viewport, the height of the flexible button
also shrinks with the box, despite the specification of 1000 pixels as the
preferred height. It continues to shrink until the minimum required height for
the button is reached, which here will likely be the height needed to display
the button's label and border. After that, the button can shrink no further.
Elements within a box can therefore have their own notions of minimum and
maximum intrinsic sizes. In the above example, the button could not get
any smaller than the minimum height required to draw its borders and its
text.
</p>
<pre>
#div1 { display: box; }
#iframe1 { box-flex: 1; min-width: 100px; max-width: 300px; height: 300px; }
<div id="div1">
<iframe id="iframe1" src="http://www.mozilla.org/"/>
</div>
</pre>
<p>
In this example, the iframe has a minimum width of 100 pixels and a maximum
width of 300 pixels. If the containing box is less than 100 pixels wide, the
iframe will overflow its containing div. If the containing box is between
100 pixels and 300 pixels inclusive, the width of the iframe would be set to that
size, minus any necessary padding, borders and margins. If the width of
the containing box is larger than 300 pixels, the extra space will be added
inside the div. The extra space is added after the iframe inside the box.
</p>
<pre>
<p style="display: box;">
<button style="box-flex: 1; max-width: 50px;">Child 1</button>
<button style="box-flex: 1; min-width: 50px;">Child 2</button>
</p>
</pre>
<p>In this example, the box has been stretched so that it is very
wide. The first child has a maximum width of 50 pixels, and it divides
the excess space equally with the second child until its maximum width
has been reached. After that, since it is not allowed to grow any
further, the remaining space all goes to the second child.
</p>
</div>
<h2 id="packing">Packing along the box axis</h2>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-pack">box-pack</dfn>
<tr valign=baseline><td><em>Value:</em> <td><span class="default">start</span> | end | center | justify
<tr valign=baseline><td><em>Initial:</em> <td>start
<tr valign=baseline><td><em>Applies to:</em> <td>box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>When all of the elements within a box are inflexible or when all elements
have grown to their maximum sizes and can stretch no further, extra space
may be left over in the box. The box-pack property may be used to dictate
how any additional space along the box-axis should be distributed between elements.
The box-pack property does not affect the position of elements in the opposite
direction. That is, box-pack affects only the horizontal position in horizontally
oriented boxes and only the vertical position in vertically oriented boxes.
</p>
<dl>
<dt>start
</dt><dd>For normal direction boxes, the left edge of the first child
is placed at the left side, with all extra space placed after the last
child. For reverse direction boxes, the right edge of the last child
is placed at the right side, with all extra space placed before the first
child.
</dd><dt>end
</dt><dd>For normal direction boxes, the right edge of the last child
is placed at the right side, with all extra space placed before the first
child. For reverse direction boxes, the left edge of the first child
is placed at the left side, with all extra space placed after the last child.
</dd><dt>center
</dt><dd>The extra space is divided evenly, with half placed before the first
child and the other half placed after the last child.
</dd><dt>justify
</dt><dd>The space is divided evenly in-between each child, with none of the
extra space placed before the first child or after the last child. If there
is only one child, treat the pack value as if it were start.
</dd></dl>
<div class="example">
<pre>
<p style="box-align: center; box-pack: center; width: 300px; height: 300px;">
<button>centered</button>
</p>
</pre>
<p> In the example above, the button is centered within the box using the
<span class="property">'box-align'</span> and
<span class="property">'box-pack'</span>
properties together. The former centers the button vertically, and the
latter centers the button horizontally.
</div>
<h2 id="multiple">Multiple Lines</h2>
<table class="propdef">
<tbody>
<tr valign=baseline><td><em>Name:</em> <td><dfn id="propdef-box-lines">box-lines</dfn>
<tr valign=baseline><td><em>Value:</em> <td><span class="default">single</span> | multiple
<tr valign=baseline><td><em>Initial:</em> <td>single
<tr valign=baseline><td><em>Applies to:</em> <td>box elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>no
<tr valign=baseline><td><em>Media:</em> <td>visual
<tr valign=baseline><td><em>Computed value:</em> <td>specified value
</tbody>
</table>
<p>By default a horizontal box will lay out its children in a single row,
and a vertical box will lay out its children in a single column. This
behavior can be changed using the box-lines property. The default value is
single, which means that all elements will be placed in a single row
or column, and any elements that don't fit will simply be considered
overflow.
</p><p>If a value of multiple is specified, however, then the box is allowed to
expand to multiple lines (that is, multiple rows or columns) in order to
accommodate all of its children. The box must attempt to fit its children
on as few lines as possible by shrinking all elements down to their minimum
widths or heights if necessary.
</p><p>If the children in a horizontal box still do not fit on a line after
being reduced to their minimum widths, then children are moved one by one
onto a new line, until the elements remaining on the previous line fit.
This process can repeat to an arbitrary number of lines. If a line contains
only a single element that doesn't fit, then the element should stay on that
line and overflow out of the box. The later lines are placed below the
earlier lines in normal direction boxes and above in reverse direction boxes.
The height of a line is the height of the largest child in that line. No
additional space appears between the lines apart from the margins on the
largest elements in each line. For calculating the height of a line, margins
with a computed value of auto should be treated as having a value of 0.
</p><p>A similar process occurs for children in a vertical box. Later lines in
normal direction boxes are placed to the right of earlier lines and to the left
in reverse direction boxes.
</p><p>Once the number of lines has been determined, elements with a computed value
for box-flex other than 0 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 and flex-groups. The packing of elements
in a line, as specified by the box-pack property, is also computed independently
for each line.
</p>
<div class="example">
<p>
This example shows four buttons that do not fit horizontally.
</p>
<pre>
#div1 {
display: box;
box-lines: multiple;
width: 300px;
}
button {
box-flex: 1.0;
width: 100px;
}
<div id="div1">
<button id="button1">Elephant</button>
<button id="button2">Tiger</button>
<button id="button1">Antelope</button>
<button id="button2">Wildebeest</button>
</div>
</pre>
<p>
The buttons are shrunk to their minimum widths, in this case calculated
intrinsically. Assume that the four buttons have a minimum intrinsic width
of 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>
<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: box;
box-lines: multiple;
box-pack: center;
width: 300px;
}
button {
box-flex: 1.0;
width: 90px;
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>
<h3 id="multiple-alignment">Multiple Lines and alignment</h3>
<p class="note">
Note: not sure what this should do yet.
</p>
<p>
The box-align property may be used to control the alignment of children in
multiple line boxes, as with single line boxes. If box-align is start, the
first line is placed along the top or left edge of the box (or the bottom
or right edge for reverse direction boxes), and additional lines are placed
afterward with no extra spacing between them. Each element within a line is
placed with that same edge aligned. For instance, in a normal direction,
vertical box, the top edges of each element are aligned with the top edge of
the line it is within. If box-align is end, the first line is placed along the
bottom or right edge of the box (or the top or left edge for reverse direction
boxes), and additional lines are placed before. Each element within a line is
placed with that same edge aligned.
</p>
<p>
If box-align is center, the extra spacing is divided evenly on both sides of
the box, and the lines placed between this space. Elements are centered within
their lines. If box-align is baseline, the elements in a line are aligned by
their baselines as with single line boxes, with space placed before or after
each element in the line as necessary. The first line is placed as with the
value start.
</p>
<p>
If box-align is stretch, then each line is stretched equally, and the elements
within each line are stretched to the size of the largest item in that line.
</p>
<h2 id="inlinesAndBlocks">Relationship to Inlines and blocks</h2>
<p>
A box placed in a block is considered a block level element and will be positioned
and sized according to the rules for CSS 2.1 (section 10.3 for widths). Specifically,
the following equation applies for calculating the width:
</p>
<blockquote>
<p>'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' + scrollbar width (if any) = width of containing block
</p>
</blockquote>
<p>All children of 'box' elements are block-level. If inline-level elements are nested
inside boxes, they get wrapped in an anonymous block which then takes part in the
box layout.
</p><p>
If the width of a child of a flexible box is computed as 'auto', then the used value
is the shrink-to-fit width. This calculation is done similarly to how the width of
a floating element is determined. Otherwise if the width has a computed value,
then that value is used as the width.
</p><p>
In a horizontally oriented box, the flexibility is then applied which may increase
or decrease the used width. In a vertically oriented box, the position and size
of the child may be adjusted by the value of the container's
<span class="property">'box-align'</span> property.
</p><p>
The <span class="property">'min-width'</span>, <span class="property">'min-height'</span>,
<span class="property">'max-width'</span>, and <span class="property">'max-height'</span>
CSS properties act the same on boxes as on blocks.
</p><p>