-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
6677 lines (6019 loc) · 277 KB
/
Overview.bs
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
<pre class='metadata'>
Title: CSS Flexible Box Layout Module Level 1
Shortname: css-flexbox
Level: 1
Status: ED
Work Status: Testing
Group: csswg
ED: https://drafts.csswg.org/css-flexbox/
TR: https://www.w3.org/TR/css-flexbox-1/
Previous Version: https://www.w3.org/TR/2018/CR-css-flexbox-1-20181119/
Previous Version: https://www.w3.org/TR/2018/CR-css-flexbox-1-20181108/
Previous Version: https://www.w3.org/TR/2017/CR-css-flexbox-1-20171019/
Previous Version: https://www.w3.org/TR/2016/CR-css-flexbox-1-20160526/
Previous Version: https://www.w3.org/TR/2016/CR-css-flexbox-1-20160301/
Previous Version: https://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/
Previous Version: https://www.w3.org/TR/2014/WD-css-flexbox-1-20140925/
Previous Version: https://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/
Previous Version: https://www.w3.org/TR/2012/CR-css3-flexbox-20120918/
Previous Version: https://www.w3.org/TR/2012/WD-css3-flexbox-20120612/
Previous Version: https://www.w3.org/TR/2012/WD-css3-flexbox-20120322/
Previous Version: https://www.w3.org/TR/2011/WD-css3-flexbox-20111129/
Previous Version: https://www.w3.org/TR/2011/WD-css3-flexbox-20110322/
Previous Version: https://www.w3.org/TR/2009/WD-css3-flexbox-20090723/
Abstract: The specification describes a CSS box model optimized for user interface design. In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Rossen Atanassov, Microsoft, ratan@microsoft.com, w3cid 49885
Former Editor: Alex Mogilevsky, Microsoft Corporation, alexmog@microsoft.com
Former Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393
Former Editor: Neil Deakin, Mozilla Corporation, enndeakin@gmail.com
Former Editor: Ian Hickson, formerly of Opera Software, ian@hixie.ch
Former Editor: David Hyatt, formerly of Netscape Corporation, hyatt@apple.com
!Issues List: <a href="https://drafts.csswg.org/css-flexbox-1/issues">https://drafts.csswg.org/css-flexbox-1/issues</a>
Ignored Terms: auto, first formatted line, first letter
Ignored Vars: item’s own max-content, maximum min-content among all items
WPT Path Prefix: css/css-flexbox/
</pre>
<pre class='link-defaults'>
spec: css21; type: property
text: margin
text: min-width
text: max-width
text: min-height
text: max-height
spec: css-break-3; type: property; text: break-after
spec: css-sizing-3;
type: value;
for: width
text: min-content
text: max-content
text: fit-content
type: property; text: box-sizing
type:dfn;
text: width
text: height
spec: css-align-3;
type: value; text: start
type:dfn; text:alignment baseline
spec: css-position-3; type: property; text: left
spec: css-writing-modes-3; type: dfn;
text: start
text: end
spec: css-pseudo-4; type: selector;
text: ::first-line
text: ::first-letter
</pre>
<style>
img { background: transparent; }
code.one-line { white-space: pre; }
.code-and-figure {
display: table;
margin: 0 auto;
border-spacing: 1em;
}
.code-and-figure > div {
display: table-cell;
vertical-align: middle;
}
ol.layout-start { counter-reset: list 0; }
ol.layout-start,
ol.continue { list-style: none; }
ol.layout-start > li,
ol.continue > li { position: relative; counter-increment: list; }
ol.layout-start > li::before,
ol.continue > li::before { content: counter(list) "."; position: absolute; left: -4.5em; width: 4em; text-align: right; }
.compact, .compact li {
margin-top: 0;
margin-bottom: 0;
}
/* Overview catalog example */
#overview-example {
display:table;
margin: 0 auto 1em;
border-spacing: .5em 0;
min-width: 672px;
color: black;
}
#overview-example > .col {
display: table-column;
background: hsl(60,100%,90%);
}
#overview-example > .desc {
display: table-cell;
vertical-align: top;
width: 300px;
padding: 1em 1em 0;
text-align: left;
border: thick solid hsl(60,80%,50%);
border-radius: 1em 1em 0 0;
border-bottom: none;
}
#overview-example > .desc > img {
margin: 0 auto;
display: block;
}
#overview-example > .desc > h1 {
background: transparent;
}
#overview-example > .buttons {
display: table-row;
}
#overview-example > .buttons > div {
display: table-cell;
border: thick solid hsl(60,80%,50%);
border-radius: 0 0 1em 1em;
border-top: none;
text-align: center;
}
#overview-example button {
background-color: hsl(120,100%,40%);
border: medium inset hsl(120,70%,40%);
border-radius: 1em;
padding: .5em;
font-weight: bold;
color: white;
font-size: 1.6em;
cursor: pointer;
width: 90%;
margin: 1em auto;
}
/* Visibility: Collapse example */
#visibility-collapse-example {
display: table;
width: 100%;
box-shadow: 3px 3px 10px canvas;
}
#visibility-collapse-example > article,
#visibility-collapse-example > nav {
display: table-cell;
}
#visibility-collapse-example > article {
width: 100%;
background: canvas;
}
#visibility-collapse-example ul,
#visibility-collapse-example li {
list-style: none;
margin: 0;
padding: 0;
}
#visibility-collapse-example > nav > ul {
background: #444;
border-radius: 0.5em;
padding: 0.075em;
}
#visibility-collapse-example li {
padding: 0 0.5em;
background: #ddd;
color: black;
border-radius: 0.40em;
border: #444 solid 0.075em;
white-space: nowrap;
}
#visibility-collapse-example li li {
background: #444;
color: white;
margin: 0 -0.5em;
border-radius: 0;
}
#visibility-collapse-example li li:first-child {
border-radius: 0.375em 0.375em 0 0;
}
#visibility-collapse-example a {
background: transparent;
color: inherit;
}
#visibility-collapse-example > nav > ul > li:target,
#visibility-collapse-example > nav > ul > li:hover {
background: #888;
color: white;
}
#visibility-collapse-example > nav > ul > li:not(:target):not(:hover) > ul {
height: 0;
overflow: hidden;
}
#auto-bar {
overflow: hidden;
padding: .25em 1em;
background: #ddd;
list-style: none;
margin: 0;
border-radius: .3em;
}
@media (prefers-color-scheme: dark) {
#auto-bar { background: #444; }
}
#auto-bar > li {
float: left;
margin: 0;
}
#auto-bar > li:first-child:after,
#auto-bar > li:first-child + li:after {
content: " | ";
white-space: pre;
}
#auto-bar > li > a {
display: inline-block;
padding: 0 .25em;
border-radius: .3em;
border: none;
background: transparent;
}
#auto-bar > li > a:not(:hover):not(:focus) {
text-decoration: none;
}
#auto-bar > li > a:hover {
color: #ddd;
background: #444;
}
#auto-bar > #login { float: right; }
.cross-auto-figure > div {
margin: 0 auto;
width: 70px;
background: #888;
padding: 0 .5em;
border-radius: 1em;
border: 1px solid transparent;
}
.cross-auto-figure > div > div {
border-spacing: 0;
display: table;
background: #ddd;
color: black;
text-align: center;
margin: .5em auto;
padding: .5em;
border-radius: .5em;
}
.axis { color: hsl( 0,80%,40%); }
.side { color: hsl(240,80%,50%); }
.size { color: hsl(120,80%,30%); }
</style>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
CSS 2.1 defined four layout modes — algorithms which determine
the size and position of boxes based on their relationships
with their sibling and ancestor boxes:
* block layout, designed for laying out documents
* inline layout, designed for laying out text
* table layout, designed for laying out 2D data in a tabular format
* positioned layout, designed for very explicit positioning without much regard for other elements in the document
This module introduces a new layout mode, <dfn export>flex layout</dfn>,
which is designed for laying out more complex applications and webpages.
<h3 id="overview">
Overview</h3>
<em>This section is not normative.</em>
Flex layout is superficially similar to block layout.
It lacks many of the more complex text- or document-centric properties
that can be used in block layout, such as
<a href="https://www.w3.org/TR/CSS2/visuren.html#floats">floats</a> and
<a href="https://www.w3.org/TR/css3-multicol/">columns</a>.
In return it gains simple and powerful tools
for distributing space and aligning content
in ways that web apps and complex web pages often need.
The contents of a flex container:
* can be laid out in any <a href="#flex-direction-property">flow direction</a>
(leftwards, rightwards, downwards, or even upwards!)
* can have their display order <a value for="flex-direction" lt="row-reverse">reversed</a> or
'order|rearranged' at the style layer
(i.e., visual order can be independent of source and speech order)
* can be laid out linearly along a single (<a lt="main axis">main</a>) axis or
<a href="#flex-wrap-property">wrapped</a> into multiple lines along a secondary (<a lt="cross axis">cross</a>) axis
* can <a href="#flexibility">“flex” their sizes</a>
to respond to the available space
* can be <a href="#alignment">aligned</a> with respect to their container or each other on the secondary (<a lt="cross axis">cross</a>)
* can be dynamically <a href="#visibility-collapse">collapsed</a> or uncollapsed
along the <a>main axis</a> while preserving the container's <a>cross size</a>
<div class='example'>
Here's an example of a catalog where each item has a title, a photo, a description, and a purchase button.
The designer's intention is that each entry has the same overall size,
that the photo be above the text,
and that the purchase buttons are aligned at the bottom, regardless of the length of the item's description.
Flex layout makes many aspects of this design easy:
* The catalog uses flex layout to lay out rows of items horizontally,
and to ensure that items within a row are all equal-height.
Each entry is then itself a column flex container,
laying out its contents vertically.
* Within each entry, the source document content is ordered logically
with the title first, followed by the description and the photo.
This provides a sensible ordering for speech rendering and in non-CSS browsers.
For a more compelling visual presentation, however,
'order' is used to pull the image up from later in the content to the top,
and 'align-self' is used to center it horizontally.
* An <a href="#auto-margins"><css>auto</css> margin</a> above the purchase button
forces it to the bottom within each entry box,
regardless of the height of that item's description.
<pre class="lang-css">
#deals {
display: flex; /* Flex layout so items <a property lt="align-self">have equal height</a> */
flex-flow: row wrap; /* <a section href="#flex-flow-property">Allow items to wrap into multiple lines</a> */
}
.sale-item {
display: flex; /* Lay out each item using flex layout */
flex-flow: column; /* <a section href="#flex-flow-property">Lay out item's contents vertically</a> */
}
.sale-item > img {
order: -1; /* Shift image before other content (in visual order) */
align-self: center; /* <a property lt="align-self">Center the image cross-wise (horizontally)</a> */
}
.sale-item > button {
margin-top: auto; /* <a section href="#auto-margins">Auto top margin pushes button to bottom</a> */
}
</pre>
<pre class="lang-markup">
<section id="deals">
<section class="sale-item">
<h1>Computer Starter Kit</h1>
<p>This is the best computer money can buy, if you don’t have much money.
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
<img src="images/computer.jpg"
alt="You get: a white computer with matching peripherals.">
<button>BUY NOW</button>
</section>
<section class="sale-item">
…
</section>
…
</section>
</pre>
<figure>
<div id="overview-example">
<div class="col"></div>
<div class="col"></div>
<div class="desc">
<img src="images/computer.jpg" alt='You get: a white computer with matching keyboard and monitor.'>
<h1 id=quiet-pubrules-1 style="font-size: 1.4em;">Computer Starter Kit</h1>
<p>
This is the best computer money can buy,
if you don't have much money.
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
</div>
<div class="desc">
<img src="images/printer.png" alt='You get: beautiful ASCII art.'>
<h1 id=quiet-pubrules-2 style="font-size: 1.4em;">Printer</h1>
<p>
Only capable of printing
ASCII art.
<ul>
<li>Paper and ink not included.
</ul>
</div>
<div class="buttons">
<div><button>BUY NOW</button></div>
<div><button>BUY NOW</button></div>
</div>
</div>
<figcaption>
An example rendering of the code above.
</figcaption>
</figure>
</div>
<h3 id="placement">
Module interactions</h3>
This module extends the definition of the 'display' property [[!CSS2]],
adding a new block-level and new inline-level display type,
and defining a new type of formatting context
along with properties to control its layout.
None of the properties defined in this module apply to the ''::first-line'' or ''::first-letter'' pseudo-elements.
The <a href="http://www.w3.org/TR/css-align/">CSS Box Alignment Module</a>
extends and supersedes the definitions of the alignment properties
('justify-content', 'align-items', 'align-self', 'align-content')
introduced here.
<h3 id="values">
Value Definitions</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.
<h2 id='box-model'>
Flex Layout Box Model and Terminology</h2>
A <dfn export>flex container</dfn> is the box generated by an element with a
computed 'display' of ''flex'' or ''inline-flex''.
In-flow children of a flex container are called <dfn export lt="flex item" id="flex-item">flex items</dfn>
and are laid out using the flex layout model.
Unlike block and inline layout,
whose layout calculations are biased to the <a href="https://www.w3.org/TR/css3-writing-modes/#abstract-box">block and inline flow directions</a>,
flex layout is biased to the <dfn export lt="flex direction">flex directions</dfn>.
To make it easier to talk about flex layout,
this section defines a set of flex flow–relative terms.
The 'flex-flow' value and the <a>writing mode</a>
determine how these terms map
to physical directions (top/right/bottom/left),
axes (vertical/horizontal), and sizes (width/height).
<figure>
<img src='images/flex-direction-terms.svg' width=665 height=277 alt>
<figcaption>
An illustration of the various directions and sizing terms as applied to a ''row'' flex container.
</figcaption>
</figure>
<dl id="main" export>
<dt class='axis'>main axis
<dt class='axis'>main dimension
<dd>
The <dfn lt="main axis|main-axis">main axis</dfn> of a flex container is the primary axis along which <a>flex items</a> are laid out.
It extends in the <dfn>main dimension</dfn>.
<dt class='side'>main-start
<dt class='side'>main-end
<dd>
The <a>flex items</a> are placed within the container
starting on the <dfn>main-start</dfn> side
and going toward the <dfn>main-end</dfn> side.
<dt class='size'>main size
<dt class='size'>main size property
<dd>
The <dfn>main size</dfn> of a [=flex container=] or [=flex item=]
refers to its [=width=] or [=height=],
whichever is in the [=main dimension=].
Its <dfn>main size property</dfn>
is either its 'width' or 'height' property,
whichever is in the [=main dimension=].
Likewise, its <dfn lt="min main size property">min</dfn> and
<dfn lt="max main size property">max main size properties</dfn>
are its 'min-width'/'max-width' or 'min-height'/'max-height' properties,
whichever are in the <a>main dimension</a>,
and determine its <dfn lt="min main size">min</dfn>/<dfn>max main size</dfn>.
In [=flex layout=], the [=main size=] is controlled by the 'flex' property
rather than directly by the [=main size property=].
Note: This means any references to a flex item's used size in the [=main dimension=]
([=width=], [=height=], [=inline size=], [=block size=])
refers to its post-flexing [=main size=].
</dl>
<dl id="cross" export>
<dt class='axis'>cross axis
<dt class='axis'>cross dimension
<dd>
The axis perpendicular to the <a>main axis</a> is called the <dfn lt="cross axis|cross-axis">cross axis</dfn>.
It extends in the <dfn>cross dimension</dfn>.
<dt class='side'>cross-start
<dt class='side'>cross-end
<dd>
<a>Flex lines</a> are filled with items and placed into the container
starting on the <dfn>cross-start</dfn> side of the flex container
and going toward the <dfn>cross-end</dfn> side.
<dt class='size'>cross size
<dt class='size'>cross size property
<dd>
The <dfn>cross size</dfn> of a [=flex container=] or [=flex item=]
refers to its [=width=] or [=height=],
whichever is in the [=cross dimension=].
Its <dfn>cross size property</dfn>
is either its 'width' or 'height' property,
whichever is in the [=cross dimension=].
Likewise, its <dfn lt="min cross size property">min</dfn> and
<dfn lt="max cross size property">max cross size properties</dfn>
are its 'min-width'/'max-width' or 'min-height'/'max-height' properties,
whichever are in the <a>cross dimension</a>,
and determine its <dfn lt="min cross size">min</dfn>/<dfn>max cross size</dfn>.
</dl>
Additional sizing terminology used in this specification
is defined in <a href="http://www.w3.org/TR/CSS-SIZING-3/">CSS Intrinsic and Extrinsic Sizing</a>. [[!CSS-SIZING-3]]
<!--
████████ ████ ██████ ████████ ██ ███ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██████ ████████ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ █████████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████████ ████ ██████ ██ ████████ ██ ██ ██
-->
<h2 id='flex-containers'>
Flex Containers: the ''flex'' and ''inline-flex'' 'display' values</h2>
<div class="informative">
<pre class="propdef partial">
Name: display
New values: flex | inline-flex
</pre>
</div>
<dl dfn-type=value dfn-for=display>
<dt><dfn>flex</dfn>
<dd>
This value causes an element to generate a <a>flex container</a> box
that is <a>block-level</a> when placed in <a>flow layout</a>.
<wpt>
display-flex-001.htm
</wpt>
<dt><dfn>inline-flex</dfn>
<dd>
This value causes an element to generate a <a>flex container</a> box
that is <a>inline-level</a> when placed in <a>flow layout</a>.
</dl>
A <a>flex container</a> establishes a new <dfn export>flex formatting context</dfn> for its contents.
This is the same as establishing a block formatting context,
except that flex layout is used instead of block layout.
For example, floats do not intrude into the flex container,
and the flex container's margins do not collapse with the margins of its contents.
<a>Flex containers</a> form a containing block for their contents
<a href="https://www.w3.org/TR/CSS2/visudet.html#containing-block-details">exactly like block containers do</a>. [[!CSS2]]
The 'overflow' property applies to <a>flex containers</a>.
Flex containers are not block containers,
and so some properties that were designed with the assumption of block layout don't apply in the context of flex layout.
In particular:
* 'float' and 'clear' do not create floating or clearance of <a>flex item</a>,
and do not take it out-of-flow.
* 'vertical-align' has no effect on a flex item.
* the ''::first-line'' and ''::first-letter'' pseudo-elements do not apply to <a>flex containers</a>,
and <a>flex containers</a> do not contribute a <a>first formatted line</a> or <a>first letter</a>
to their ancestors.
<!--
Issue: When the Pseudo-Elements spec exists,
align this language with whatever algo we define for figuring out where to search for first-line/letter content.
-->
If an element's specified 'display' is ''inline-flex'',
then its 'display' property computes to ''flex''
in certain circumstances:
the table in <a href="https://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Section 9.7</a>
is amended to contain an additional row,
with ''inline-flex'' in the "Specified Value" column
and ''flex'' in the "Computed Value" column.
<!--
████████ ██ ████████ ██ ██ ████ ████████ ████████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ███ ███ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██
██████ ██ ██████ ███ ██ ██ ██████ ██ ███ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████████ ████████ ██ ██ ████ ██ ████████ ██ ██ ██████
-->
<h2 id='flex-items'>
Flex Items</h2>
Loosely speaking, the <a>flex items</a> of a <a>flex container</a>
are boxes representing its in-flow contents.
Each in-flow child of a <a>flex container</a>
becomes a <a>flex item</a>,
and each child <a>text sequence</a>
is wrapped in an <a>anonymous</a> <a>block container</a> <a>flex item</a>.
However, if the entire <a>text sequences</a> contains only
[=document white space characters=]
(i.e. characters that can be affected by the 'white-space' property)
it is instead not rendered (just as if its <a>text nodes</a> were ''display:none'').
<wpt>
anonymous-flex-item-001.html
anonymous-flex-item-002.html
anonymous-flex-item-003.html
anonymous-flex-item-004.html
anonymous-flex-item-005.html
anonymous-flex-item-006.html
</wpt>
<div class="example">
<p>Examples of flex items:
<pre class="lang-markup">
<div style="display:flex">
<!-- flex item: block child -->
<div id="item1">block</div>
<!-- flex item: floated element; floating is ignored -->
<div id="item2" style="float: left;">float</div>
<!-- flex item: anonymous block box around inline content -->
anonymous item 3
<!-- flex item: inline child -->
<span>
item 4
<!-- flex items do not <a href="https://www.w3.org/TR/CSS2/visuren.html#anonymous-block-level">split</a> around blocks -->
<q style="display: block" id=not-an-item>item 4</q>
item 4
</span>
</div>
</pre>
<figure>
<figcaption>Flex items determined from above code block</figcaption>
<a href="examples/flex-item-determination.html">
<object type="image/png" data="images/flex-item-determination.png">
<ol>
<li>Flex item containing <samp>block</samp>.
<li>Flex item containing <samp>float</samp>.
<li>(Anonymous, unstyleable) flex item containing <samp>anonymous item 3</samp>.
<li>Flex item containing three blocks in succession:
<ul>
<li>Anonymous block containing <samp>item 4</samp>.
<li><code><q></code> element block containing <samp>item 4</samp>.
<li>Anonymous block containing <samp>item 4</samp>.
</ul>
</ol>
</object>
</a>
</figure>
Note that the inter-element white space disappears:
it does not become its own flex item,
even though the inter-element text <em>does</em> get wrapped in an anonymous flex item.
Note also that the anonymous item's box is unstyleable,
since there is no element to assign style rules to.
Its contents will however inherit styles (such as font settings) from the flex container.
</div>
A <a>flex item</a> [=establishes an independent formatting context=] for its contents.
However, flex items themselves are <dfn export>flex-level</dfn> boxes, not block-level boxes:
they participate in their container's flex formatting context,
not in a block formatting context.
<hr>
Note: Authors reading this spec may want to
<a href="#item-margins">skip past the following box-generation and static position details</a>.
If the [=computed value|computed=] 'display' value of an element's nearest ancestor element
(skipping ''display:contents'' ancestors)
is ''flex'' or ''inline-flex'',
the element's own 'display' value is [=blockified=].
(See <a href="https://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS2.1§9.7</a> [[!CSS2]]
and [[css-display-3#transformations]]
for details on this type of 'display' value conversion.)
Note: Blockification still occurs even when the ''flex'' or ''inline-flex'' element does not end up generating a [=flex container=] box,
e.g. when it is [=replaced element|replaced=]
or in a ''display: none'' subtree.
Note: Some values of 'display' normally trigger the creation of anonymous boxes around the original box.
If such a box is a <a>flex item</a>,
it is blockified first,
and so anonymous box creation will not happen.
For example, two contiguous <a>flex items</a> with ''display: table-cell''
will become two separate ''display: block'' <a>flex items</a>,
instead of being wrapped into a single anonymous table.
In the case of flex items with ''display: table'',
the table wrapper box becomes the <a>flex item</a>,
so the 'align-self' property applies to it.
The contents of any caption boxes contribute to the calculation of
the table wrapper box's min-content and max-content sizes.
However, like 'width' and 'height', the 'flex' longhands apply to the table box as follows:
the <a>flex item</a>’s final size is calculated
by performing layout as if the distance between
the table wrapper box's edges and the table box's content edges
were all part of the table box's border+padding area,
and the table box were the <a>flex item</a>.
<!--
███ ████████ ██████ ████████ ███████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ████████ ██████ ████████ ██ ██ ██████
█████████ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ████████ ██████ ██ ███████ ██████
-->
<h3 id='abspos-items'>
Absolutely-Positioned Flex Children</h3>
As it is out-of-flow,
an absolutely-positioned child of a <a>flex container</a> does not participate in flex layout.
The [=cross-axis=] edges of the [=static-position rectangle=]
of an absolutely-positioned child of a <a>flex container</a>
are the [=content edges=] of the [=flex container=].
The [=main-axis=] edges of the [=static-position rectangle=]
are where the [=margin edges=] of the child would be positioned
if it were the sole <a>flex item</a> in the <a>flex container</a>,
assuming both the child and the flex container
were fixed-size boxes of their used size.
(For this purpose,
the child's ''margin/auto'' margins are treated as zero.)
<wpt>
abspos/abspos-autopos-htb-ltr.html
abspos/abspos-autopos-htb-rtl.html
abspos/abspos-autopos-vlr-ltr.html
abspos/abspos-autopos-vlr-rtl.html
abspos/abspos-autopos-vrl-ltr.html
abspos/abspos-autopos-vrl-rtl.html
</wpt>
<div class='example'>
The effect of this is that if you set, for example,
''align-self: center;'' on an absolutely-positioned child of a <a>flex container</a>,
auto offsets on the child will center it in the <a>flex container's</a> <a>cross axis</a>.
</div>
<h3 id='item-margins'>
Flex Item Margins and Paddings</h3>
The margins of adjacent <a>flex items</a> do not
<a href="https://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapse</a>.
Percentage margins and paddings on <a>flex items</a>,
like those on <a>block boxes</a>,
are resolved against the <a>inline size</a> of their <a>containing block</a>,
e.g. left/right/top/bottom percentages
all resolve against their <a>containing block</a>’s <em>width</em>
in horizontal <a>writing modes</a>.
Auto margins expand to absorb extra space in the corresponding dimension.
They can be used for alignment,
or to push adjacent flex items apart.
See <a href="#auto-margins">Aligning with <span class=css>auto</span> margins</a>.
<h3 id='painting'>
Flex Item Z-Ordering</h3>
<a>Flex items</a> paint exactly the same as inline blocks [[!CSS2]],
except that 'order'-modified document order is used in place of raw document order,
and 'z-index'
values other than ''z-index/auto'' create a stacking context
even if 'position' is ''static''
(behaving exactly as if 'position' were ''relative'').
Note: Descendants that are positioned outside a flex item still participate
in any stacking context established by the flex item.
<!--
██████ ███████ ██ ██ ███ ████████ ██████ ████████ ████████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ████████ ██████ ██████ ██ ██
██ ██ ██ ██ ██ █████████ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ████████ ████████ ██ ██ ██ ██████ ████████ ████████
-->
<h3 id='visibility-collapse'>
Collapsed Items</h3>
Specifying ''visibility:collapse'' on a flex item
causes it to become a <dfn export lt="collapsed flex item" local-lt="collapsed">collapsed flex item</dfn>,
producing an effect similar to ''visibility:collapse'' on a table-row or table-column:
the [=collapsed flex item=] is removed from rendering entirely,
but leaves behind a "strut" that keeps the flex line's cross-size stable.
Thus, if a flex container has only one flex line,
dynamically collapsing or uncollapsing items
may change the <a>flex container</a>'s <a>main size</a>, but
is guaranteed to have no effect on its <a>cross size</a>
and won't cause the rest of the page's layout to "wobble".
Flex line wrapping <em>is</em> re-done after collapsing, however,
so the cross-size of a flex container with multiple lines might or might not change.
Though [=collapsed flex items=] aren't rendered,
they do appear in the <a href="https://www.w3.org/TR/CSS2/intro.html#formatting-structure">formatting structure</a>.
Therefore, unlike on ''display:none'' items [[!CSS2]],
effects that depend on a box appearing in the formatting structure
(like incrementing counters or running animations and transitions)
still operate on collapsed items.
<div class="example">
In the following example,
a sidebar is sized to fit its content.
''visibility: collapse'' is used to dynamically hide parts of a navigation sidebar
without affecting its width, even though the widest item (“Architecture”)
is in a collapsed section.
<figure>
<figcaption>Sample live rendering for example code below</figcaption>
<div id="visibility-collapse-example">
<!-- No, don't look at this source code, look at the other source code. -->
<nav>
<ul>
<li id="nav-about"><a href="#nav-about">About</a>
<ul>
<li><a href="#">History</a>
<li><a href="#">Mission</a>
<li><a href="#">People</a>
</ul>
<li id="nav-projects"><a href="#nav-projects">Projects</a>
<ul>
<li><a href="#">Art</a>
<li><a href="#">Architecture</a>
<li><a href="#">Music</a>
</ul>
<li id="nav-interact"><a href="#nav-interact">Interact</a>
<ul>
<li><a href="#">Blog</a>
<li><a href="#">Forums</a>
<!-- li><a href="#">Events</a> -->
</ul>
</ul>
</nav>
<article>
Hover over the menu to the left:
each section expands to show its sub-items.
In order to keep the sidebar width (and this main area width) stable,
''visibility: collapse'' is used instead of ''display: none''.
This results in a sidebar that is always wide enough for the word “Architecture”,
even though it is not always visible.
</article>
</div>
</figure>
<pre class="lang-css">
@media (min-width: 60em) {
/* <a href="https://www.w3.org/TR/css3-mediaqueries/#width">two column layout only when enough room</a> (relative to default text size) */
div { display: flex; }
#main {
flex: 1; /* <a href="#flexibility">Main takes up all remaining space</a> */
order: 1; /* Place it after (to the right of) the navigation */
min-width: 12em; /* Optimize main content area sizing */
}
}
/* menu items use flex layout so that visibility:collapse will work */
nav > ul > li {
display: flex;
flex-flow: column;
}
/* dynamically collapse submenus when not targeted */
nav > ul > li:not(:target):not(:hover) > ul {
visibility: collapse;
}
</pre>
<pre class="lang-markup">
<div>
<article id="main">
Interesting Stuff to Read
</article>
<nav>
<ul>
<li id="nav-about"><a href="#nav-about">About</a>
…
<li id="nav-projects"><a href="#nav-projects">Projects</a>
<ul>
<li><a href="…">Art</a>
<li><a href="…">Architecture</a>
<li><a href="…">Music</a>
</ul>
<li id="nav-interact"><a href="#nav-interact">Interact</a>
…
</ul>
</nav>
</div>
<footer>
…
</pre>
</div>
To compute the size of the strut, flex layout is first performed with all items uncollapsed,
and then re-run with each [=collapsed flex item=] replaced by a strut that maintains
the original cross-size of the item's original line.
See the <a href="#layout-algorithm">Flex Layout Algorithm</a>
for the normative definition of how ''visibility:collapse''
interacts with flex layout.
Note: Using ''visibility:collapse'' on any flex items
will cause the flex layout algorithm to repeat partway through,
re-running the most expensive steps.
It's recommended that authors continue to use ''display:none'' to hide items
if the items will not be dynamically collapsed and uncollapsed,
as that is more efficient for the layout engine.
(Since only part of the steps need to be repeated when 'visibility' is changed,
however, 'visibility: collapse' is still recommended for dynamic cases.)
<!--
██ ██ ████ ██ ██
███ ███ ██ ███ ██ ██ ██
████ ████ ██ ████ ██ ██ ██
██ ███ ██ ██ ██ ██ ██ ███████ █████████
██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ███ ██ ██
██ ██ ████ ██ ██
-->
<h3 id="min-size-auto">
Automatic Minimum Size of Flex Items</h3>
Note: The ''min-width/auto'' keyword,
representing an <a>automatic minimum size</a>,
is the new initial value of the 'min-width' and 'min-height' properties.
The keyword was previously defined in this specification,
but is now defined in the [[!CSS-SIZING-3|CSS Sizing]] module.
To provide a more reasonable default <a>minimum size</a> for <a>flex items</a>,
the used value of a <a>main axis</a> <a>automatic minimum size</a>
on a <a>flex item</a> whose [=computed value|computed=] 'overflow' value is [=non-scrollable overflow value|non-scrollable=]
is its [=content-based minimum size=];
for <a>scroll containers</a> the <a>automatic minimum size</a> is zero, as usual.
The <dfn>content-based minimum size</dfn> of a [=flex item=]
differs depending on whether the [=flex item=] is [=replaced element|replaced=] or not:
: For [=replaced elements=]
::
Use the smaller of the [=content size suggestion=]
and the [=transferred size suggestion=]
(if one exists),
capped by the [=specified size suggestion=]
(if one exists).
: For [=non-replaced elements=]
::
Use the larger of the [=content size suggestion=]
and the [=transferred size suggestion=]
(if one exists),
capped by the [=specified size suggestion=]
(if one exists).
In either case,
the size is clamped by the [=maximum size|maximum=] [=main size=]
if it's <a>definite</a>.
<!-- This differs from Grid's definition
(which just consults the first of specified,transferred,content that exists)
because we explicitly want to let flex items shrink to their min-content size.
Grid doesn't have similarly meaningful shrinkability, so it doesn't need to care. -->
The <a>content size suggestion</a>, <a>specified size suggestion</a>, and <a>transferred size suggestion</a>
used in this calculation account for the relevant min/max/preferred size properties
so that the <a>content-based minimum size</a> does not interfere with any author-provided constraints,
and are defined below:
<dl>
<dt><dfn>specified size suggestion</dfn>
<dd>