-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
1589 lines (1184 loc) · 58.1 KB
/
Overview.html
File metadata and controls
1589 lines (1184 loc) · 58.1 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 href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet
type="text/css">
<link href="../default.css" rel=stylesheet type="text/css">
<body>
<div class=head>
<h1 id=head-box-flexible>Flexible Box Layout Module</h1>
<h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 31 July 2009</h2>
<dl>
<dt>This version:
<dd><!-- <a href="http://www.w3.org/TR/2009/WD-css3-flexbox-20090731/">http://www.w3.org/TR/2009/WD-css3-flexbox-20090731/</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>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>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2009 <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.org/"><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><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. <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> 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).
<h2 class="no-num no-toc" id=table><a name=contents>Table of contents</a></h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#overview"><span class=secno>1 </span>Overview</a>
<li><a href="#orientation"><span class=secno>2 </span>Orientation</a>
<li><a href="#displayorder"><span class=secno>3 </span>Display order</a>
<li><a href="#alignment"><span class=secno>4 </span>Alignment</a>
<li><a href="#flex"><span class=secno>5 </span>Flexibility</a>
<li><a href="#packing"><span class=secno>6 </span>Packing along the box
axis</a>
<li><a href="#multiple"><span class=secno>7 </span>Multiple Lines</a>
<ul class=toc>
<li><a href="#multiple-alignment"><span class=secno>7.1 </span>Multiple
Lines and alignment</a>
</ul>
<li><a href="#inlinesAndBlocks"><span class=secno>8 </span>Relationship to
Inlines and blocks</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>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property">Property index</a>
</ul>
<!--end-toc-->
<hr>
<h2 id=overview><span class=secno>1 </span>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> In CSS, flexible boxes (often referred to only as boxes in this
specification) may be created by setting the <span
class=property>‘<code class=property>display</code>’</span>
property. A block-level box can be specified with a value of <span
class=css>‘<code class=property>box</code>’</span> and an
inline box can be specified using a value of <span
class=css>inline-box</span>.
<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> 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 ‘<code class=property>pre</code>’).
<p> Children of boxes may specify their width and height using the <span
class=property>‘<code class=property>width</code>’</span> and
<span class=property>‘<code
class=property>height</code>’</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 ‘<code
class=property>auto</code>’, 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 ‘<code
class=property>auto</code>’, then the used value in a similar
manner.
<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> 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>‘<code class=property><a
href="#propdef-box-orient">box-orient</a></code>’</span> and <span
class=property>‘<code class=property><a
href="#propdef-box-direction">box-direction</a></code>’</span>
properties, and order specified by the <span class=property>‘<code
class=property><a
href="#propdef-box-ordinal-group">box-ordinal-group</a></code>’</span>
property. They are aligned within the box according to the <span
class=property>‘<code class=property><a
href="#propdef-box-align">box-align</a></code>’</span> property. The
boxes may then flex or be distributed as specified by the <span
class=property>‘<code class=property><a
href="#propdef-box-flex">box-flex</a></code>’</span>, <span
class=property>‘<code class=property><a
href="#propdef-box-flex-group">box-flex-group</a></code>’</span>,
<span class=property>‘<code class=property><a
href="#propdef-box-pack">box-pack</a></code>’</span> and <span
class=property>‘<code class=property><a
href="#propdef-box-lines">box-lines</a></code>’</span> properties.
<p> The <span class=property>‘<code
class=property>float</code>’</span> and <span
class=property>‘<code class=property>clear</code>’</span>
properties do not apply to children of box elements, so the used value for
these properties is ‘<code class=property>none</code>’. These
properties do apply to the box itself if it is not a child of another box.
<div class=example>
<p> For example:</p>
<pre>
<p style="width: 400px;">
<button style=&quo
6C3A
t;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>‘<code
class=property>overflow</code>’</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>
<h2 id=orientation><span class=secno>2 </span>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
</table>
<p> A box may lay out its children either horizontally or vertically.
<dl>
<dt>horizontal
<dd>The box displays its children from left to right in a horizontal line.
<dt>vertical
<dd>The box displays its children from stacked from top to bottom
vertically.
<dt>inline-axis
<dd>The box displays its children along the inline axis.
<dt>block-axis
<dd>The box displays its children along the block axis.
</dl>
<p> The inline and block axes are the writing-mode dependent keywords
which, in English, map to horizontal and vertical respectively.
<h2 id=displayorder><span class=secno>3 </span>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.
<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
</table>
<p> The <span class=property>‘<code class=property><a
href="#propdef-box-direction">box-direction</a></code>’</span>
property specifies the direction in which children of a box are displayed.
<dl>
<dt>normal
<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.
<dt>reverse
<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.
</dl>
<p> If the computed value for the box's ‘<code
class=property>direction</code>’ property is ‘<code
class=property>normal</code>’, 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 ‘<code
class=property>direction</code>’ property is ‘<code
class=property>reverse</code>’, 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> When the computed value for the overflow property is ‘<code
class=property>visible</code>’, ‘<code
class=property>scroll</code>’ or ‘<code
class=property>auto</code>’, 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.
<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
</table>
<p>The children of a box element may be assigned to <dfn
id=ordinal0>ordinal groups</dfn> using the <span
class=property>‘<code class=property><a
href="#propdef-box-ordinal-group">box-ordinal-group</a></code>’</span>
property. This property is a natural number value with an initial value is
1.
<p>Ordinal groups can be used in conjunction with the ‘<code
class=property><a
href="#propdef-box-direction">box-direction</a></code>’ 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>‘<code
class=property>visibility</code>’</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">‘<code class=property>box-sizing</code>’</span>
property determines how the <span class="property">‘<code class=property>height</code>’</span> and
<span class="property">‘<code class=property>width</code>’</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">‘<code class=property>box-sizing</code>’</span> applies to block and
table-level elements as well as boxes.
-->
<h2 id=alignment><span class=secno>4 </span>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
</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>‘<code
class=property><a
href="#propdef-box-align">box-align</a></code>’</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>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>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
<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.
<dt>end
<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.
<dt>center
<dd>Any extra space is divided evenly, with half placed above the child
and the other half placed after the child.
<dt>baseline
<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 ‘<code
class=property>auto</code>’ 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>.
<dt>stretch
<dd>The height of each child is adjusted to that of the containing block.
However, note the text below.
</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 ‘<code class=property><a
href="#propdef-box-align">box-align</a></code>’ below.
<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-box-align">box-align</a></code>’</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 ‘<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 box-align was start.
<p>If the value of <span class=property>‘<code class=property><a
href="#propdef-box-align">box-align</a></code>’</span> is start,
center, baseline, or end, 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 box-align value.
<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.
<h2 id=flex><span class=secno>5 </span>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> 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.)
<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
</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
</table>
<p>An element is flexible when the <a class=property
href="#propdef-box-flex">box-flex</a> property is specified. The <a
class=property href="#propdef-box-flex">box-flex</a> 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>‘<code class=property><a
href="#propdef-box-flex-group">box-flex-group</a></code>’</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> 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> 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>‘<code class=property>float</code>’</span>
property does not apply to children of flexible boxes, they are considered
part of normal flow and flexibility does apply.
<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> 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.
<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>‘<code class=css>box-flex of child</code>’ / ‘<code
class=css>total of box-flex values of child and all siblings</code>’
<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> 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> 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> For vertically oriented boxes, the algorithm as described above is
similar except using the height instead of the width.
<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.
<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;">