-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
1384 lines (1151 loc) · 57 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
<h1>CSS Box Alignment Module Level 3</h1>
<pre class='metadata'>
Shortname: css-align
Level: 3
Group: csswg
Status: ED
Work Status: Revising
ED: https://drafts.csswg.org/css-align/
TR: https://www.w3.org/TR/css-align-3/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Previous Version: https://www.w3.org/TR/2014/WD-css-align-3-20141218/
Previous Version: https://www.w3.org/TR/2013/WD-css3-align-20130514/
Previous Version: https://www.w3.org/TR/2012/WD-css3-align-20120612/
Abstract: This module contains the features of <a href="https://www.w3.org/TR/CSS/">CSS</a> relating to the alignment of boxes within their containers in the various CSS box layout models: block layout, table layout, flex layout, and grid layout. (The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].)
Link Defaults: selectors-3 (dfn) first formatted line, css-flexbox-1 (dfn) flex line, css-multicol-1 (dfn) multi-column element, css-fonts-3 (dfn) first available font, css21 (property) max-width/max-height/min-width/min-height, css-writing-modes-3 (dfn) dominant baseline, css-position-3 (property) left, css-cascade-3 (value) initial
Ignored Terms: table cell, stretch
At Risk: ''last-baseline''
</pre>
<style type="text/css">
.issue th:first-child { text-align: left !important; }
[rowspan] > img { float: right; }
[rowspan] { vertical-align: middle; }
table small { display: block; }
table.align-details { width: 100%; }
.align-details th { font: inherit; white-space: nowrap; width: 1em; }
</style>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
CSS Levels 1 and 2 allowed for the alignment of text via 'text-align'
and the alignment of blocks by balancing ''margin/auto'' margins.
However, except in table cells,
vertical alignment was not possible.
As CSS3 adds further capabilities,
the ability to align boxes in various dimensions becomes more critical.
This module attempts to create a cohesive and common box alignment model to share among all of CSS.
Note: The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].
Inspiration for this document:
<ul>
<li><a href="http://wiki.csswg.org/ideas/centering#alignment-property">summary of a discussion for implementing <CENTER></a>
<li><a href="https://lists.w3.org/Archives/Member/w3c-css-wg/2008AprJun/0015.html">Minutes from March 2008 F2F</a>
<li><a href="http://lists.w3.org/Archives/Public/www-style/2012Feb/0743.html">fantasai's attempt to merge all alignment properties</a>
</ul>
<h3 id="placement">
Module interactions</h3>
This module adds some new alignment capabilities
to the block layout model described in [[!CSS21]] chapters 9 and 10
and defines the interaction of these properties
with the alignment of table cell content using 'vertical-align',
as defined in [[!CSS21]] chapter 17.
The interaction of these properties with
Grid Layout [[!CSS3-GRID-LAYOUT]]
and Flexible Box Layout [[!CSS3-FLEXBOX]]
is defined in their respective modules.
The property definitions here supersede those in [[!CSS3-FLEXBOX]]
(which have a smaller, earlier subset of permissible values).
No properties in this module apply to the <code>::first-line</code>
or <code>::first-letter</code> pseudo-elements.
<h3 id="values">
Values</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]].
Value types not defined in this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].
Other CSS modules may expand the definitions of these value types:
for example [[CSS3VAL]], when combined with this module,
adds the ''initial'' keyword as a possible property value.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the
<a href="https://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.
<h2 id="overview">
Overview of Alignment Properties</h2>
The <dfn export>box alignment properties</dfn> in CSS are a set of 6 properties
that control alignment of boxes within other boxes.
They can be described along two axises:
<ul>
<li>which dimension they apply to (main/inline vs. cross/block), and
<li>whether they control the position of the box within its parent, or the box's content within itself.
</ul>
Note: This specification uses the terms “justify” and “align” to distinguish
between alignment in the main/inline and cross/block dimensions, respectively.
The choice is somewhat arbitrary, but having the two terms allows for
a consistent naming scheme that works across all of CSS's layout models.
The following table summarizes the <a>box alignment properties</a>
and the display types they can apply to.
<table class=data>
<colgroup span=1></colgroup>
<colgroup span=2></colgroup>
<colgroup span=1></colgroup>
<thead>
<tr>
<th>Common
<th>Axis
<th>Aligns
<th>Applies to
<tbody>
<tr>
<th>'justify-content'
<td>main/inline
<td rowspan=2>
<img src="images/content-example.svg" width=106 height=106 alt="">
content within element
<small>(effectively adjusts padding)</small>
<td>block containers, <a>flex containers</a>, and <a>grid containers</a>
<tr>
<th>'align-content'
<td>cross/block
<td>block containers, <a>flex containers</a>, and <a>grid containers</a>
<tbody>
<tr>
<th>'justify-self'
<td>inline
<td rowspan=2>
<img src="images/self-example.svg" width=106 height=106 alt="">
element within parent
<small>(effectively adjusts margins)</small>
<td>block-level elements and <a>grid items</a>
<tr>
<th>'align-self'
<td>cross/block
<td><a>flex items</a> and <a>grid items</a>
<tbody>
<tr>
<th>'justify-items'
<td>inline
<td rowspan=2>
<img src="images/items-example.svg" width=106 height=106 alt="">
items inside element
<small>(controls child items’ ''align/justify-self: auto'')</small>
<td><a>grid containers</a>
<tr>
<th>'align-items'
<td>cross/block
<td><a>flex containers</a> and <a>grid containers</a>
</table>
Note: The '*-items' values don't affect the element itself.
When set on a flex container or grid container,
they specify the interpretation of any ''*-self: auto'' used on the items in the container element.
<h2 id='alignment-values'>
Alignment Values</h2>
All of the alignment properties use a common set of values,
defined below.
<dl>
<dt><dfn export>alignment subject</dfn>
<dd>
The <a>alignment subject</a> is the thing or things being aligned by the property.
For 'justify-self' and 'align-self',
the <a>alignment subject</a> is the margin box of the box the property is set on.
For 'justify-content' and 'align-content',
the <a>alignment subject</a> is defined by the layout mode.
<dt><dfn export>alignment container</dfn>
<dd>
The <a>alignment container</a> is the rectangle that the <a>alignment subject</a> is aligned within.
This is defined by the layout mode,
but is usually the <a>alignment subject</a>’s containing block.
</dl>
<h3 id='positional-values'>
Positional Alignment: the ''center'', ''start'', ''end'', ''self-start'', ''self-end'', ''flex-start'', ''flex-end'', ''left'', and ''right'' keywords</h3>
The positional alignment keywords specify a position for an <a>alignment subject</a>
with respect to its <a>alignment container</a>.
The <<self-position>> set of values is used by 'justify-self' and 'align-self'
to align the box within its <a>alignment container</a>,
and also by 'justify-items' and 'align-items'
(to specify default values for 'justify-self' and 'align-self').
The <<content-position>> set of values is used by 'justify-content' and 'align-content'
to align the box's contents within itself.
<pre class='prod'>
<dfn><self-position></dfn> = center | start | end | self-start | self-end |
flex-start | flex-end | left | right;
<dfn><content-position></dfn> = center | start | end | flex-start | flex-end | left | right;
</pre>
Values have the following meanings:
<dl dfn-type="value">
<dt><dfn for="<self-position>, <content-position>">center</dfn> <small>(self, content)</small>
<dd>Centers the <a>alignment subject</a> within its <a>alignment container</a>.
<dt><dfn for="<self-position>, <content-position>">start</dfn> <small>(self, content)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s start edge in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>">end</dfn> <small>(self, content)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s end edge in the appropriate axis.
<dt><dfn for="<self-position>">self-start</dfn> <small>(self)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s start side in the appropriate axis.
<dt><dfn for="<self-position>">self-end</dfn> <small>(self)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s end side in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>">flex-start</dfn> <small>(self, content)</small>
<dd><strong>Only used in flex layout.</strong> [[!CSS3-FLEXBOX]]
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-start or cross-start side, as appropriate.
When used on boxes that are not children of a <a>flex container</a>,
this value behaves as ''start''.
<dt><dfn for="<self-position>, <content-position>">flex-end</dfn> <small>(self, content)</small>
<dd><strong>Only used in flex layout.</strong>
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-end or cross-end side, as appropriate.
When used on boxes that are not children of a <a>flex container</a>,
this value behaves as ''end''.
<dt><dfn for="<self-position>, <content-position>">left</dfn> <small>(self, content)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-left">line-left</a> edge.
If the property's axis is not parallel with the inline axis,
this value behaves as ''start''.
<dt><dfn for="<self-position>, <content-position>">right</dfn> <small>(self, content)</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-right">line-right</a> edge.
If the property's axis is not parallel with the inline axis,
this value behaves as ''start''.
</dl>
<p class='issue'>
Add example images.
<p class='issue'>
Make it easier to understand the dual-axis nature of "start" and "end" wrt orthogonal flows.
<h3 id='baseline'>
Baseline Alignment: the ''baseline'' and ''last-baseline'' keywords</h3>
<dfn export>Baseline alignment</dfn> is a form of positional alignment
that aligns multiple <a>alignment subjects</a>
within a <a>shared alignment context</a>
(such as cells within a row or column)
by matching up their <a>alignment baselines</a>.
The baseline alignment keywords are:
<pre class='prod'>
<dfn><baseline-position></dfn> = baseline | last-baseline
</pre>
and are defined below:
<dl dfn-type=value dfn-for="justify-content, justify-self, justify-items, align-content, align-self, align-items, <baseline-position>">
<dt><dfn>baseline</dfn>
<dd>
Indicates <dfn dfn for export>first-baseline alignment</dfn>:
aligns one of baselines in the box's <a>first baseline set</a>
in the appropriate axis
with the corresponding <a>first baselines</a>
of all the boxes in its <a>baseline-sharing group</a>.
If the <a>alignment subject</a>’s position is not fully determined by <a>baseline alignment</a>,
the content is ''start''-aligned insofar as possible while preserving the baseline alignment.
(Content that has no <a>first baselines</a> is thus start-aligned.)
<dt><dfn>last-baseline</dfn>
<dd>
Indicates <dfn dfn for export>last-baseline alignment</dfn>:
aligns one of baselines in the box's <a>last baseline set</a>
in the appropriate axis
with the corresponding <a>last baselines</a>
of all the boxes in its <a>baseline-sharing group</a>.
If the <a>alignment subject</a>’s position is not fully determined by <a>baseline alignment</a>,
the content is ''end''-aligned insofar as possible while preserving the baseline alignment.
(Content that has no <a>last baselines</a> is thus end-aligned.)
</dl>
These values give a box a <dfn export>baseline alignment preference</dfn>:
either “first” or “last”, respectively.
When specified for 'align-content'/'justify-content',
these values trigger <a>baseline content-alignment</a>,
shifting the content of the box within its content box,
and may also affect the sizing of the box itself.
See [[#baseline-align-content]].
When specified for 'align-self'/'justify-self',
these values trigger <a>baseline self-alignment</a>,
shifting the entire box within its container,
which may affect the sizing of its container.
See [[#baseline-align-self]].
If both <a>baseline content-alignment</a> <em>and</em> <a>baseline self-alignment</a> are specified in the same axis on the same box,
only <a>baseline self-alignment</a> is honored in that axis;
the content-alignment in that axis must be treated as ''start''.
<p class='issue'>Add example images here.
Note: The 'vertical-align' property will also need a ''first-baseline'' value
because per CSS2.1 for inline blocks, ''baseline'' is equivalent to ''last-baseline''.
<h3 id='distribution-values'>
Distributed Alignment: the ''<content-distribution>/stretch'', ''space-between'', ''space-around'', and ''space-evenly'' keywords</h3>
The distribution values are used by 'justify-content' and 'align-content'
to distribute the <a>alignment subjects</a>
evenly between the start and end edges of the <a>alignment container</a>.
When the <a>alignment subjects</a> cannot be distributed in this way,
they behave as their <dfn export>fallback alignment</dfn>.
Each distribution value has an associated <<content-position>> as a <a>fallback alignment</a>,
but one can alternatively be explicitly specified in the property.
<pre class='prod'> <dfn><content-distribution></dfn> = space-between | space-around | space-evenly | stretch</pre>
<dl dfn-type="value" dfn-for="align-content, justify-content, <content-distribution>">
<dt><dfn>space-between</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>.
The first <a>alignment subject</a> is placed flush with the start edge of the <a>alignment container</a>,
the last <a>alignment subject</a> is placed flush with the end edge of the <a>alignment container</a>,
and the remaining <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same.
Unless otherwise specified,
this value falls back to ''start''.
<dt><dfn>space-around</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a half-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same,
and the spacing before the first and after the last <a>alignment subject</a> is half the size of the other spacing.
Unless otherwise specified,
this value falls back to ''center''.
<dt><dfn>space-evenly</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a full-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a>,
before the first <a>alignment subject</a>,
and after the last <a>alignment subject</a>
is the same.
Unless otherwise specified,
this value falls back to ''center''.
<dt><dfn>stretch</dfn>
<dd>
If the combined size of the <a>alignment subjects</a> is less than the size of the <a>alignment container</a>,
any <css>auto</css>-sized <a>alignment subjects</a> have their size increased equally (not proportionally),
while still respecting the constraints imposed by 'max-height'/'max-width'
(or equivalent functionality),
so that the combined size exactly fills the <a>alignment container</a>.
Unless otherwise specified,
this value falls back to ''flex-start''.
<span class='note'>(For layout modes other than flex layout, ''flex-start'' is identical to ''start''.)</span>
</dl>
<p class='issue'>
Add even more example images.
<h3 id='overflow-values'>
Overflow Alignment: the ''safe'' and ''unsafe'' keywords</h3>
When the <a>alignment subject</a> is larger than the <a>alignment container</a>,
it will overflow.
Some alignment modes, if honored in this situation,
may cause data loss:
for example, if the contents of a sidebar are centered,
when they overflow they may send part of their boxes past the viewport's start edge,
which can't be scrolled to.
To help combat this problem,
an <dfn export>overflow alignment</dfn> mode can be explicitly specified.
"Unsafe" alignment honors the specified alignment mode in overflow situations, even if it causes data loss,
while "safe" alignment changes the alignment mode in overflow situations in an attempt to avoid data loss.
If the <a>overflow alignment</a> isn't explicitly specified,
the default <a>overflow alignment</a> is ''unsafe''.
<pre class='prod'><dfn><overflow-position></dfn> = unsafe | safe</pre>
<dl dfn-type="value" dfn-for="<overflow-position>">
<dt><dfn>safe</dfn>
<dd>
If the size of the <a>alignment subject</a> overflows the <a>alignment container</a>,
the <a>alignment subject</a> is instead aligned as if the alignment mode were ''start''.
<dt><dfn>unsafe</dfn>
<dd>
Regardless of the relative sizes of the <a>alignment subject</a> and <a>alignment container</a>,
the given alignment value is honored.
</dl>
Issue: Should we add a third (default) value that overflows up until the point that it would overflow into an unscrollable region?
This is probably what's actually needed;
we can't default to "safe" because of Flexbox,
but this slight tweak to "unsafe" is probably safe compat-wise,
and would help users on small screens.
<div class='example'>
The figure below illustrates the difference in "safe" versus "unsafe" centering,
using a column flexbox as an example:
<figure>
<style scoped>
.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;
}
</style>
<div style="display:table; margin: 0 auto 1em;">
<div style="display:table-cell; padding-right: 50px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div>Authoritarianism</div>
<div>Blog</div>
</div>
</div>
<div style="display:table-cell; padding-left: 50px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div style="margin-left: -31px;">Authoritarianism</div>
<div>Blog</div>
</div>
</div>
</div>
<figcaption>
The items in the figure on the left are set to ''align-self: safe center;'',
while those in the figure on the right are set to ''align-self: unsafe center;''.
If this column <a>flex container</a> was placed against the left edge of the page,
the "safe" behavior would be more desirable,
as the long item would be fully readable.
In other circumstances,
the "unsafe" centering behavior might be better,
as it correctly centers all the items.
</figcaption>
</figure>
</div>
<!--
██████ ███████ ██ ██ ████████ ████████ ██ ██ ████████
██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ███ ██ ██
██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██
█████████ ███████ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ███ ██
██████ ███████ ██ ██ ██ ████████ ██ ██ ██
-->
<h2 id='content-distribution'>
Content Distribution: the 'justify-content' and 'align-content' properties</h2>
The <dfn export>content distribution properties</dfn> 'justify-content' and 'align-content'
control alignment of the box's content within its content box.
<div class="figure">
<img alt="Diagram showing that the alignment of the content within the element is affected." src="images/content-example.svg" width=212 height=212>
</div>
<pre class="propdef">
Name: justify-content, align-content
Value: normal | <<baseline-position>> | <<content-distribution>> || [ <<overflow-position>>? && <<content-position>> ]
Initial: normal
Applies to: block containers, flex containers, and grid containers
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value
Animatable: no
</pre>
Aligns the contents of the box as a whole.
Values other than <dfn value for="justify-content, align-content">normal</dfn> are defined in [[#alignment-values]], above.
If both a <<content-distribution>> and <<content-position>> are given,
the <<content-position>> provides an explicit <a>fallback alignment</a>.
Details per Layout Mode {#distribution-details}
-----------------------------------------------
### Block Containers ### {#distribution-block}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>block container</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
The entire contents of the block, as a unit.
<tr>
<th>'align-content' Axis
<td>
The <a>block axis</a>.
If a <<content-distribution>> is specified
the <a>fallback alignment</a> is used instead.
<tr>
<th>'justify-content' Axis
<td>
Does not apply to and has no effect on <a>block containers</a>.
<tr>
<th>''justify-content/normal'' Behavior
<td>
All values other than ''justify-content/normal'' force the block container to establish a new formatting context.
For table cells, the behavior of the ''justify-content/normal'' depends on the computed value of 'vertical-align':
''vertical-align/top'' makes it behave as ''start'',
''vertical-align/middle'' makes it behave as ''center'',
''vertical-align/bottom'' makes it behave as ''end'',
and all other values make it behave as ''baseline''.
''justify-content/normal'' otherwise behaves as ''start''.
</table>
### Multicol Containers ### {#distribution-multicol}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>multi-column element</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
The column boxes, as a unit.
Issue: Should this apply to column like it does grid tracks?
''justify-content/normal'' would act as ''stretch'', giving the current behavior.
<tr>
<th>'align-content' Axis
<td>
The <a>block axis</a>.
If a <<content-distribution>> is specified
the <a>fallback alignment</a> is used instead.
<tr>
<th>'justify-content' Axis
<td>
Does not apply to and has no effect on <a>multi-column elements</a>.
<tr>
<th>''justify-content/normal'' Behavior
<td>
''justify-content/normal'' behaves as ''start''.
</table>
### Flex Containers ### {#distribution-flex}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>flex container</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
For 'justify-content',
the <a>flex items</a> in each <a>flex line</a>.
For 'align-content',
the <a>flex lines</a>.
<tr>
<th>'align-content' Axis
<td>
The <a>cross axis</a>.
<tr>
<th>'justify-content' Axis
<td>
The 'justify-content' property applies along the <a>main axis</a>,
but since flexing in the <a>main axis</a> is controlled by 'flex',
''<content-distribution>/stretch'' behaves as ''flex-start''
(ignoring the specified <a>fallback alignment</a>, if any).
<tr>
<th>''justify-content/normal'' Behavior
<td>
''justify-content/normal'' behaves as ''<content-distribution>/stretch''.
</table>
See [[!CSS-FLEXBOX-1]] for details.
### Grid Containers ### {#distribution-grid}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>grid container</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
The <a>grid tracks</a>.
<tr>
<th>'align-content' Axis
<td>
The <a lt="block axis">block (column) axis</a>,
aligning the <a>grid rows</a>.
<tr>
<th>'justify-content' Axis
<td>
The <a lt="inline axis">inline (row) axis</a>,
aligning the <a>grid columns</a>.
<tr>
<th>''justify-content/normal'' Behavior
<td>
''justify-content/normal'' behaves as ''stretch''.
</table>
See [[!CSS-GRID-1]] for details.
<h3 id="baseline-align-content">
Baseline Content-Alignment</h3>
The content of boxes participating in row-like layout contexts (<a>shared alignment contexts</a>)
can be baseline-aligned to each other.
This effectively increases the padding on the box
to align the <a>alignment baseline</a> of its contents
with that of other baseline-aligned boxes in its <a lt="baseline-sharing group">group</a>.
The set of boxes that participate in <a>baseline content-alignment</a>
depends on the layout model:
<dl>
<dt>Table Cells:
<dd>
A <a>table cell</a> participates in first (last) <a>baseline content-alignment</a>
in either its row or column (whichever matches its <a>inline axis</a>)
if its computed 'align-content' is ''baseline'' (''last-baseline'').
<dt>Flex Items:
<dd>
A <a>flex item</a> participates in first (last) <a>baseline content-alignment</a>
in its flex line if
its computed 'align-content' is ''baseline'' (''last-baseline''),
its <a>inline axis</a> is parallel to the <a>main axis</a>,
and its computed 'align-self' is ''align-self/stretch'' or ''self-start'' (''self-end'').
For this purpose,
the ''start'', ''end'', ''flex-start'', and ''flex-end'' values of 'align-self'
are treated as either ''self-start'' or ''self-end'',
whichever they end up equivalent to.
<dt>Grid Items:
<dd>
A <a>grid item</a> participates in first (last) <a>baseline content-alignment</a>
in either its row or column (whichever matches its <a>inline axis</a>)
if its computed 'align-content' is ''baseline'' (''last-baseline''),
and its computed 'align-self' or 'justify-self' (whichever affects its <a>block axis</a>)
is ''align-self/stretch'' or ''self-start'' (''self-end'').
For this purpose,
the ''start'', ''end'', ''flex-start'', and ''flex-end'' values of 'align-self'
are treated as either ''self-start'' or ''self-end'',
whichever they end up equivalent to.
</dl>
If a box spans multiple <a>shared alignment contexts</a>,
it participates in first (last) <a>baseline content-alignment</a>
within its start-most (end-most) <a>shared alignment context</a> along that axis.
When a box participates in first (last) <dfn export lt="baseline content-alignment|first-baseline content-alignment|last-baseline content-alignment">baseline content-alignment</dfn>
it aligns its contents as follows:
its <a>alignment subject</a> (i.e. content)
is aligned to the start (end) edge of its <a>alignment container</a> (i.e. itself)
and the minimum necessary extra space is added <strong>between its start (end) content edge and its <a>alignment subject</a>’s edge</strong>
to align its <a>alignment baseline</a> in that axis with those of its <a>baseline-sharing group</a>.
See [[#align-by-baseline]].
This increases the intrinsic size of the box.
Note: In other words, a box participating in <a>baseline content-alignment</a>
acts like its 'padding' was increased
so that its <a>alignment baseline</a> lines up with the <a>alignment baselines</a> of its participating siblings.
The box itself is aligned as usual for its 'align-self'/'justify-self' value.
<h3 id="overflow-scroll-position">
Overflow and Scroll Positions</h3>
The <a>content distribution properties</a> also affect the initial scroll position,
setting it to display the appropriate portion of the scrollable area.
In other words,
the <a>scrollable overflow region</a> is aligned relative to the viewport
as specified by the <a>content distribution property</a>.
<div class='example'>
For example,
if a scrollable flex container is set to ''justify-content: flex-end''
(or ''justify-content: flex-start'' with ''flex-flow: row-reverse''),
it will be initially displayed scrolled all the way to the main-end edge of the scrollable area,
and its content will overflow its main-start edge.
</div>
Issue: This needs to be integrated with overflow-anchor, when the property exists,
so that you get the same behavior whether an elements *starts out* overflowing,
or is filled element-by-element.
<!--
██████ ████████ ██ ████████
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██
█████████ ███████ ██████ ██████ ██ ██████
██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
██████ ████████ ████████ ██
-->
<h2 id='self-alignment'>
Self-Alignment: Aligning the Box within its Parent</h2>
The 'justify-self' and 'align-self' properties control alignment of the box within its containing block.
<div class="figure">
<img alt="Diagram showing that the alignment of the element within its containing block is affected." src="images/self-example.svg" width=212 height=212>
</div>
<h3 id='justify-self-property'>
Inline/Main-Axis Alignment: the 'justify-self' property</h3>
<pre class="propdef">
Name: justify-self
Value: auto | normal | stretch | <<baseline-position>> | [ <<overflow-position>>? && <<self-position>> ]
Initial: auto
Applies to: block-level boxes, absolutely-positioned boxes, and grid items
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value, except for ''justify-self/auto'' (see prose)
Animatable: no
</pre>
Justifies the box within its containing block along the inline/row/main axis:
the box's outer edges are aligned within its <a>alignment container</a>
<a href="#alignment-values">as described by its alignment value</a>.
The <dfn value for="justify-self">auto</dfn> keyword computes to
the computed value of 'justify-items' on the parent
(minus any ''legacy'' keywords),
or ''justify-self/normal'' if the box has no parent.
The <dfn value for="justify-self">normal</dfn> keyword
represents the “default” alignment for the layout mode.
Its behavior depends on the layout mode, as described below.
When the box’s computed 'width'/'height' (as appropriate to the axis) is ''width/auto''
and neither of its margins (in the appropriate axis) are ''margin/auto'',
the <dfn value for="justify-self, align-self">stretch</dfn> keyword
sets the box’s used size to the length necessary to make its outer size
as close to filling the <a>alignment container</a> as possible
while still respecting the constraints imposed by 'min-height'/'min-width'/'max-height'/'max-width'.
Unless otherwise specified, this value falls back to ''flex-start''.
Issue: Should ''justify-self/stretch'' allow a fallback alignment,
like it does on 'align-content' and 'justify-content'?
Note: The ''justify-self/stretch'' keyword can cause elements to shrink,
to fit their container.
All other values are as defined in [[#alignment-values]], above.
Note: ''margin/auto'' margins,
because they effectively adjust the size of the margin area,
take precedence over 'justify-self'.
### Block-Level Boxes ### {#justify-block}
<table class="data align-details">
<tr>
<th>'justify-self' Axis
<td>
The block’s containing block’s <a>inline axis</a>.
<tr>
<th><a>Alignment Container</a>
<td>
The block's containing block,
except that for block-level elements that establish a block formatting context
and are placed next to a float,
the <a>alignment container</a> is reduced by the space taken up by the float.
Issue: This is the legacy behavior of HTML <code>align</code>.
Do we want to still do this,
or should we do the centering behavior of margins,
which center while <em>ignoring</em> floats,
then shift if necessary to avoid overlapping?
<tr>
<th><a>Alignment Subject</a>
<td>
The block's margin box.
<tr>
<th>''justify-self/normal'' Behavior
<td>
Behaves as ''justify-self/start''.
<tr>
<th>Other Details
<td>
In terms of CSS2.1 block-level formatting [[!CSS21]],
the rules for “over-constrained” computations in <a href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">section 10.3.3</a>
are ignored in favor of alignment as specified here
and the used value of the offset properties are not adjusted to correct for the over-constraint.
This property does not apply to floats.
</table>
<div class="example">
The effect of these rules is that an auto-sized block-level table,
for example, can be aligned while still having side margins.
If the table's max-content size is narrower than its containing block,
then it is shrink-wrapped to that size and aligned as specified.
If the table's max-content size is wider, then it fills its containing block,
and the margins provide appropriate spacing from the containing block edges.
</div>
### Absolutely-Positioned Boxes ### {#justify-abspos}
<table class="data align-details">
<tr>
<th>'justify-self' Axis
<td>
The block’s containing block’s <a>inline axis</a>.
<tr>
<th><a>Alignment Container</a>
<td>
The box's containing block,
as modified by the offset properties ('top'/'right'/'bottom'/'left').
<tr>
<th><a>Alignment Subject</a>
<td>
The box's margin box.
<tr>
<th>''justify-self/normal'' Behavior
<td>
For consistency with CSS 2.1,
the ''justify-self/normal'' keyword behaves as ''start'' on replaced absolutely-positioned boxes,
and behaves as ''justify-self/stretch'' on all other absolutely-positioned boxes.
If the box has non-''top/auto'' offsets in this axis,
and either 'margin' in this axis is ''margin/auto'',
an ''width/auto'' 'width' is treated as ''fill-available''
and ''margin/auto'' margins are treated as zero.
(Otherwise, when 'justify-content' is not ''justify-content/normal'',
''width: auto'' is treated as ''width/fit-content''
and ''margin/auto'' margins are used for alignment
as in in-flow block-level layout.)
<tr>
<th>Other Details
<td>
In terms of CSS2.1 formatting [[!CSS21]],
the rules for “over-constrained” computations in <a href="https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width">section 10.3.7</a>
are ignored in favor of alignment as specified here,
and the used value of the offset properties are not adjusted to correct for the over-constraint.
Values other than ''justify-self/stretch'' cause <a href="https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width">non-replaced absolutely-positioned boxes</a>
to use <a>fit-content sizing</a> for calculating ''width/auto'' inline sizes.
Note that ''justify-self/stretch'' does cause replaced absolutely-positioned elements to fill their containing block
just as non-replaced ones do.
If either offset property in this dimension is ''top/auto'',
'justify-self' has no effect.
</table>
### Table Cells ### {#justify-cell}
This property does not apply to table cells,
because their position and size is fully constrained by table layout.
### Flex Items ### {#justify-flex}
This property does not apply to <a>flex items</a>,
because there is more than one item in the <a>main axis</a>.
See 'flex' for stretching and 'justify-content' for <a>main-axis</a> alignment. [[!CSS-FLEXBOX-1]]
### Grid Items ### {#justify-grid}
<table class="data align-details">
<tr>
<th>'justify-self' Axis
<td>
The grid’s <a>row axis</a>.
<tr>
<th><a>Alignment Container</a>
<td>
The <a>grid area</a>.
<tr>
<th><a>Alignment Subject</a>
<td>
The <a>grid item’s</a> margin box.
<tr>
<th>''justify-self/normal'' Behavior
<td>
Behaves as ''justify-self/stretch''.
</table>
<h3 id='align-self-property'>
Block/Cross-Axis Alignment: the 'align-self' property</h3>
<pre class="propdef">
Name: align-self
Value: auto | normal | stretch | <<baseline-position>> | [ <<overflow-position>>? && <<self-position>> ]
Initial: auto
Applies to: flex items, grid items, and absolutely-positioned boxes
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value, except for ''align-self/auto'' (see prose)
Animatable: no
</pre>
Aligns the box within its containing block along the block/column/cross axis:
the box's outer edges are aligned within its <a>alignment container</a>
<a href="#alignment-values">as described by its alignment value</a>.
The <dfn value for="align-self">auto</dfn> keyword computes to
the computed value of 'align-items' on the parent
or ''align-self/normal'' if the box has no parent.
The <dfn value for="align-self">normal</dfn> keyword
represents the “default” alignment for the layout mode.
The ''align-self/stretch'' keyword is as defined in [[#justify-self-property]].
All other values are as defined in [[#alignment-values]], above.
Note: ''margin/auto'' margins,
because they effectively adjust the size of the margin area,
take precedence over 'justify-self'.
### Block-Level Boxes ### {#align-block}
The 'align-self' property does not apply to block-level boxes
(including floats),
because there is more than one item in the <a>block axis</a>.
### Absolutely-Positioned Boxes ### {#align-abspos}
<table class="data align-details">
<tr>
<th>'align-self' Axis
<td>
The block’s containing block’s <a>block axis</a>.
<tr>
<th><a>Alignment Container</a>
<td>
The box's containing block.
<tr>
<th><a>Alignment Subject</a>
<td>
The box’s margin box.
<tr>
<th>''align-self/normal'' Behavior
<td>
For consistency with CSS 2.1,
the ''align-self/normal'' keyword behaves as ''start'' on replaced absolutely-positioned boxes,
and behaves as ''align-self/stretch'' on all other absolutely-positioned boxes.
If the box has non-''top/auto'' offsets in this axis,
and either 'margin' in this axis is ''margin/auto'',
an ''width/auto'' 'height' is treated as ''fill-available''
and ''margin/auto'' margins are treated as zero.
(Otherwise, when 'align-content' is not ''align-content/normal'',
''height: auto'' is treated as ''height/fit-content''
and ''margin/auto'' margins are used for alignment
as in in-flow block-level layout.)
<tr>
<th>Other Details
<td>
In terms of CSS2.1 formatting [[!CSS21]],
the rules for "over-constrained" computations in <a href="https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height">section 10.6.4</a>
are ignored in favor of alignment as specified here
and the used value of the offset properties are not adjusted to correct for the over-constraint.