Skip to content

Commit ab6fd75

Browse files
committed
Rewrite of flex-align.
1 parent 35f2baa commit ab6fd75

2 files changed

Lines changed: 108 additions & 259 deletions

File tree

css3-flexbox/Overview.html

Lines changed: 83 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
<h1 id=head-box-flexible>CSS Flexible Box Layout Module</h1>
1818

19-
<h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 25 August 2011</h2>
19+
<h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 27 August 2011</h2>
2020

2121
<dl>
2222
<dt>This version:
2323

24-
<dd><!-- <a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20110825/">http://www.w3.org/TR/2011/WD-css3-flexbox-20110825/</a></dd> -->
24+
<dd><!-- <a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20110827/">http://www.w3.org/TR/2011/WD-css3-flexbox-20110827/</a></dd> -->
2525
<a
2626
href="http://dev.w3.org/csswg/css3-flexbox/">http://dev.w3.org/csswg/css3-flexbox/</a>
2727

@@ -281,7 +281,12 @@ <h2 id=box-model><span class=secno>2. </span> The Flexbox Box Model</h2>
281281
side of the flexbox, and go toward the <dfn id=main-end>main-end</dfn>
282282
side. A <a href="#flexbox-item"><i>flexbox item's</i></a> width or height,
283283
whichever is in the <a href="#main-axis"><i>main axis</i></a>, is the
284-
item's <dfn id=main-size>main size</dfn>. These terms are mapped to
284+
item's <dfn id=main-size>main size</dfn>. The <a
285+
href="#flexbox-item"><i>flexbox item's</i></a> &lsquo;<code
286+
class=property>width</code>&rsquo; or &lsquo;<code
287+
class=property>height</code>&rsquo; property, specifically, that is in the
288+
<a href="#main-axis"><i>main axis</i></a> is the item's <dfn
289+
id=main-size-property>main size property</dfn>. These terms are mapped to
285290
physical directions based on the first keyword in the &lsquo;<a
286291
href="#flex-flow0"><code class=property>flex-flow</code></a>&rsquo;
287292
property.
@@ -292,11 +297,15 @@ <h2 id=box-model><span class=secno>2. </span> The Flexbox Box Model</h2>
292297
directions and sides defined. The width or height of a <a
293298
href="#flexbox-item"><i>flexbox item</i></a>, whichever is in the <a
294299
href="#cross-axis"><i>cross axis</i></a>, is the item's <dfn
295-
id=cross-size>cross size</dfn>. These terms are mapped to physical
296-
directions based on the orientation of the <a href="#main-axis"><i>main
297-
axis</i></a> and the second keyword in the &lsquo;<a
298-
href="#flex-flow0"><code class=property>flex-flow</code></a>&rsquo;
299-
property.
300+
id=cross-size>cross size</dfn>, and similarly the actual &lsquo;<code
301+
class=property>width</code>&rsquo; or &lsquo;<code
302+
class=property>height</code>&rsquo; property, whichever is in the <a
303+
href="#cross-axis"><i>cross axis</i></a>, is the item's <dfn
304+
id=cross-size-property>cross size property</dfn>. These terms are mapped
305+
to physical directions based on the orientation of the <a
306+
href="#main-axis"><i>main axis</i></a> and the second keyword in the
307+
&lsquo;<a href="#flex-flow0"><code
308+
class=property>flex-flow</code></a>&rsquo; property.
300309

301310
<p>The contents of a flexbox can be easily and powerfully manipulated with
302311
a handful of properties. Most significantly, <a
@@ -1109,12 +1118,12 @@ <h3 id=flex-pack><span class=secno>5.1. </span> Main Axis Alignment: the
11091118

11101119
<p>Between and around <a href="#flexbox-item"><i>flexbox items</i></a>
11111120
there are additional flexible lengths called <dfn id=packing-space
1112-
title="packing space|packing spaces">packing spaces</dfn>. <a
1113-
href="#packing-space"><i>Packing spaces</i></a> can absorb leftover free
1114-
space in a flexbox line if there aren't any other <a
1115-
href="#flexible-length0"><i>flexible lengths</i></a>, or if all the <a
1116-
href="#flexible-length0"><i>flexible lengths</i></a> have reached their
1117-
maximum size. The &lsquo;<a href="#flex-pack0"><code
1121+
title="packing space|packing spaces">packing spaces</dfn>. After the
1122+
flexbox items have a chance <a href="#packing-space"><i>Packing
1123+
spaces</i></a> can absorb leftover free space in a flexbox line if there
1124+
aren't any other <a href="#flexible-length0"><i>flexible lengths</i></a>,
1125+
or if all the <a href="#flexible-length0"><i>flexible lengths</i></a> have
1126+
reached their maximum size. The &lsquo;<a href="#flex-pack0"><code
11181127
class=property>flex-pack</code></a>&rsquo; property defines the
11191128
flexibility of <a href="#packing-space"><i>packing spaces</i></a>:
11201129

@@ -1185,7 +1194,7 @@ <h3 id=flex-align><span class=secno>5.2. </span> Cross Axis Alignment: the
11851194
<tr>
11861195
<th>Value:
11871196

1188-
<td>before | after | middle | stretch | baseline
1197+
<td>start | end | center | baseline | stretch
11891198

11901199
<tr>
11911200
<th>Initial:
@@ -1195,7 +1204,7 @@ <h3 id=flex-align><span class=secno>5.2. </span> Cross Axis Alignment: the
11951204
<tr>
11961205
<th>Applies to:
11971206

1198-
<td>flexbox items
1207+
<td><a href="#flexbox-item"><i>flexbox items</i></a>
11991208

12001209
<tr>
12011210
<th>Inherited:
@@ -1213,216 +1222,92 @@ <h3 id=flex-align><span class=secno>5.2. </span> Cross Axis Alignment: the
12131222
<td>visual
12141223
</table>
12151224

1216-
<p>When the size of the containing box along <a href="#cross-axis"><i>cross
1217-
axis</i></a> is larger than the size of a child, extra space will be
1218-
available. The &lsquo;<a href="#flex-align0"><code
1219-
class=property>flex-align</code></a>&rsquo; property specifies how flexbox
1220-
item is placed along the <a href="#cross-axis"><i>cross axis</i></a>, and
1221-
where the extra space, if any, is positioned.
1222-
1223-
<p>The values of this property have the following meanings. See text for
1224-
more specifics as to how children are positioned.
1225+
<p>The &lsquo;<a href="#flex-align0"><code
1226+
class=property>flex-align</code></a>&rsquo; property aligns <a
1227+
href="#flexbox-item"><i>flexbox items</i></a> within the current line of
1228+
the flexbox &mdash; essentially the same thing as &lsquo;<a
1229+
href="#flex-pack0"><code class=property>flex-pack</code></a>&rsquo;, only
1230+
in the <a href="#cross-axis"><i>cross axis</i></a>.
12251231

12261232
<dl>
12271233
<dt><dfn id=flex-align-before>before</dfn>
12281234

1229-
<dd>The &lsquo;<a href="#flex-line-pack-before"><code
1230-
class=property>before</code></a>&rsquo; edge of the child box along <a
1231-
href="#cross-axis"><i>cross axis</i></a>is aligned with &lsquo;<a
1232-
href="#flex-line-pack-before"><code
1233-
class=property>before</code></a>&rsquo; edge of the flexbox content box.
1234-
See text for explanation of how direction of <a
1235-
href="#cross-axis"><i>cross axis</i></a> is determined.
1235+
<dd>The <a href="#cross-start"><i>cross-start</i></a> margin edge of the
1236+
<a href="#flexbox-item"><i>flexbox item</i></a> is placed flush with the
1237+
<a href="#cross-start"><i>cross-start</i></a> edge of the line.
12361238

12371239
<dt><dfn id=flex-align-after>after</dfn>
12381240

1239-
<dd>The &lsquo;<a href="#flex-line-pack-after"><code
1240-
class=property>after</code></a>&rsquo; edge of the child box along <a
1241-
href="#cross-axis"><i>cross axis</i></a>is aligned with &lsquo;<a
1242-
href="#flex-line-pack-after"><code class=property>after</code></a>&rsquo;
1243-
edge of the flexbox content box. See text for explanation of how
1244-
direction of <a href="#cross-axis"><i>cross axis</i></a> is determined.
1241+
<dd>The <a href="#cross-end"><i>cross-end</i></a> margin edge of the <a
1242+
href="#flexbox-item"><i>flexbox item</i></a> is placed flush with the <a
1243+
href="#cross-end"><i>cross-end</i></a> edge of the line.
12451244

12461245
<dt><dfn id=flex-align-middle>middle</dfn>
12471246

1248-
<dd>Any extra space along the <a href="#cross-axis"><i>cross axis</i></a>
1249-
is divided evenly, with half placed before the child and the other half
1250-
placed after the child.
1247+
<dd>The <a href="#flexbox-item"><i>flexbox item's</i></a> margin box is
1248+
centered in the <a href="#cross-axis"><i>cross axis</i></a> within the
1249+
line.
12511250

12521251
<dt><dfn id=flex-align-baseline>baseline</dfn>
12531252

12541253
<dd>
1255-
<p>If this child's inline axis is parallel to <a
1256-
href="#main-axis"><i>main axis</i></a> of the flexbox, the baseline of
1257-
the child box is aligned with baselined of all other child boxes that
1258-
meet the same criteria. Baseline of each child box is determined in the
1259-
same way as when it is placed inline (as inline-block, inline-table,
1260-
etc.).</p>
1261-
1262-
<p>The children participating in baseline alignment, once aligned on
1263-
their baselines, should then be placed into the box so that the child
1264-
with the earliest extent margin has its &lsquo;<a
1265-
href="#flex-line-pack-before"><code
1266-
class=property>before</code></a>&rsquo; margin edge flush with the
1267-
&lsquo;<a href="#flex-line-pack-before"><code
1268-
class=property>before</code></a>&rsquo; edge of flexbox's content area.
1269-
If the flexbox does not have an &lsquo;<code
1270-
class=css>auto</code>&rsquo; height, overflow will always be on the
1271-
&lsquo;<a href="#flex-line-pack-after"><code
1272-
class=property>after</code></a>&rsquo; edge.
1273-
1274-
<p>If the child box <i>inline axis</i> is orthogonal to flexbox <a
1275-
href="#main-axis"><i>main axis</i></a>, then &lsquo;<a
1276-
href="#flex-align-baseline"><code class=css>baseline</code></a>&rsquo;
1277-
acts identically to &lsquo;<a href="#flex-pack-center"><code
1278-
class=css>center</code></a>&rsquo;.</p>
1254+
<p>If the <a href="#flexbox-item"><i>flexbox item's</i></a> inline axis
1255+
is the same as the <a href="#cross-axis"><i>cross axis</i></a>, this
1256+
value is identical to &lsquo;<a href="#flex-pack-start"><code
1257+
class=css>start</code></a>&rsquo;.</p>
1258+
1259+
<p>Otherwise, all <a href="#flexbox-item"><i>flexbox items</i></a> on the
1260+
line with &lsquo;<code class=css>flex-align:baseline</code>&rsquo; that
1261+
don't run afoul of the previous paragraph are aligned such that their
1262+
baselines align, and the item with the largest distance between its
1263+
baseline and its <a href="#cross-start"><i>cross-start</i></a> margin
1264+
edge is placed flush against the <a
1265+
href="#cross-start"><i>cross-start</i></a> edge of the line.</p>
12791266

12801267
<dt><dfn id=flex-align-stretch>stretch</dfn>
12811268

1282-
<dd>The height of each child is adjusted to that of the containing block.
1283-
However, note the text below.
1269+
<dd>
1270+
<p>If the <a href="#cross-size-property"><i>cross size property</i></a>
1271+
of the <a href="#flexbox-item"><i>flexbox item</i></a> is anything other
1272+
than &lsquo;<code class=css>auto</code>&rsquo;, this value is identical
1273+
to &lsquo;<a href="#flex-pack-start"><code
1274+
class=css>start</code></a>&rsquo;.</p>
1275+
1276+
<p>Otherwise, this value causes the <a
1277+
href="#cross-size-property"><i>cross size property</i></a> of the <a
1278+
href="#flexbox-item"><i>flexbox item</i></a> to resolve to the length
1279+
necessary to make the <a href="#cross-size"><i>cross size</i></a> of the
1280+
item's margin box the same size as the line.</p>
12841281
</dl>
12851282

1286-
<p>Direction of the <a href="#cross-axis"><i>cross axis</i></a> is
1287-
determined as follows:
1288-
1289-
<p>In multi-line flexbox, <a href="#cross-axis"><i>cross axis</i></a>
1290-
points in the direction of wrapping (the side where lines are added)
1291-
1292-
<p>In single-line flexbox, the direction of <a href="#cross-axis"><i>cross
1293-
axis</i></a> is determined by the computed value of writing mode of the
1294-
flexbox element.
1295-
1296-
<ul>
1297-
<li> If flexbox's <a href="#main-axis"><i>main axis</i></a> is parallel to
1298-
inline axis of the writing mode, <a href="#cross-axis"><i>cross
1299-
axis</i></a> points in the direction of block flow.
1300-
1301-
<li> If flexbox's <a href="#main-axis"><i>main axis</i></a> is parallel to
1302-
block flow axis of the writing mode, <a href="#cross-axis"><i>cross
1303-
axis</i></a> points in the direction of inline flow
1304-
</ul>
1305-
1306-
<p>The following rules should be applied when determining the size of child
1307-
boxes along the <a href="#cross-axis"><i> cross axis</i></a>. Exceptions
1308-
to these rules are noted under each of the possible values of &lsquo;<a
1309-
href="#flex-align0"><code class=property>flex-align</code></a>&rsquo;
1310-
below.
1311-
1312-
<p>First, the <a href="#cross-axis"><i>cross axis</i></a> size of content
1313-
box of the flexbox has to be calculated. If computed value of flexbox's
1314-
width or height (whichever is along the <a href="#cross-axis"><i>cross
1315-
axis</i></a>), that value is used. If it is &lsquo;<code
1316-
class=property>auto</code>&rsquo;, the size is determined by flexbox
1317-
items, as follows:
1318-
1319-
<ol>
1320-
<li><i>Cross-axis</i> sizes of margin boxes of all children in are checked
1321-
and the biggest is selected.
1322-
1323-
<li>If there are any children with baseline alignemnt, biggest ascent
1324-
(including its margin-before) and biggest descent (including its
1325-
margin-after) are found.
1326-
1327-
<li>Flexbox's content box size is the size its biggest child or the sum of
1328-
the biggest ascent and biggest descent, whichever is larger.
1329-
</ol>
1330-
1331-
<p>All normal flow children of boxes will attempt to satisfy the following
1332-
sizing equation when placed inside vertical boxes if and only if at least
1333-
one of the specified values is auto:
1334-
1335-
<p>&lsquo;<code class=property>margin-left</code>&rsquo; + &lsquo;<code
1336-
class=property>border-left-width</code>&rsquo; + &lsquo;<code
1337-
class=property>padding-left</code>&rsquo; + &lsquo;<code
1338-
class=property>width</code>&rsquo; + &lsquo;<code
1339-
class=property>padding-right</code>&rsquo; + &lsquo;<code
1340-
class=property>border-right-width</code>&rsquo; + &lsquo;<code
1341-
class=property>margin-right</code>&rsquo; = width of containing box
1342-
1343-
<p>and a similar equation for height when placed inside horizontal boxes:
1344-
1345-
<p>&lsquo;<code class=property>margin-top</code>&rsquo; + &lsquo;<code
1346-
class=property>border-top-width</code>&rsquo; + &lsquo;<code
1347-
class=property>padding-top</code>&rsquo; + &lsquo;<code
1348-
class=property>height</code>&rsquo; + &lsquo;<code
1349-
class=property>padding-bottom</code>&rsquo; + &lsquo;<code
1350-
class=property>border-bottom-width</code>&rsquo; + &lsquo;<code
1351-
class=property>margin-bottom</code>&rsquo; = height of containing box
1352-
1353-
<p>If all the values in the equation are specified (i.e., if there are no
1354-
auto values), then the equation above does not apply, and the specified
1355-
values should be used. If applying the equation results in a negative
1356-
value for width/height, then that value is set to 0, and those values
1357-
should be used.
1358-
1359-
<p>If the value of &lsquo;<a href="#flex-align0"><code
1360-
class=property>flex-align</code></a>&rsquo; is &lsquo;<a
1361-
href="#flex-align-stretch"><code class=css>stretch</code></a>&rsquo;, then
1362-
elements obey the sizing rules specified above. This is the default value.
1363-
If both width/height and one or both margin values are &lsquo;<code
1364-
class=property>auto</code>&rsquo;, the &lsquo;<code
1365-
class=property>auto</code>&rsquo; margins are set to 0 and the equation is
1366-
used to find a value for width/height. Otherwise, if both margins are
1367-
&lsquo;<code class=property>auto</code>&rsquo;, then the equation is
1368-
solved under the additional constraint that the two margins must get the
1369-
same value. If neither the width/height or either margin is auto, then the
1370-
extra space is positioned as if flex-align was &lsquo;<a
1371-
href="#flex-line-pack-before"><code
1372-
class=property>before</code></a>&rsquo;.
1373-
1374-
<p>If the value of &lsquo;<a href="#flex-align0"><code
1375-
class=property>flex-align</code></a>&rsquo; is &lsquo;<a
1376-
href="#flex-line-pack-before"><code class=css>before</code></a>&rsquo;,
1377-
&lsquo;<a href="#flex-line-pack-after"><code
1378-
class=css>after</code></a>&rsquo;, &lsquo;<a
1379-
href="#flex-line-pack-middle"><code class=css>middle</code></a>&rsquo;, or
1380-
&lsquo;<a href="#flex-align-baseline"><code
1381-
class=css>baseline</code></a>&rsquo;, and a value of &lsquo;<code
1382-
class=css>auto</code>&rsquo; is specified for width/height, then the
1383-
intrinsic size (or shrink to fit size) of the element should be used. If
1384-
one margin has the value of auto, then the equations above should be used.
1385-
If both margins have a value of auto then the above equations should be
1386-
used, with the space being divided evenly between the two margins. These
1387-
rules are similar to the rules for replaced elements inside blocks.
1388-
1389-
<p>If the above would cause the width or height to greater than the
1390-
computed maximum width or height, then the width or height is set to the
1391-
maximum width or height, and the auto margins increased by the extra
1392-
amount left over. If both margins are auto, they should both be increased
1393-
by the same amount. If neither margin is auto, the extra space is placed
1394-
as necessary depending on the flex-align value.
1395-
1396-
<p>Once the sizes are computed, the margin boxes of the elements should be
1397-
aligned at the before, middle, baseline or after edge of the box.
1398-
13991283
<div class=example>
1400-
<p>A vertical flexbox can be used to emulate the functionality of HTML's
1401-
<code>&lt;center></code> element:</p>
1284+
<p>By using a vertical flexbox and &lsquo;<a href="#flex-align0"><code
1285+
class=property>flex-align</code></a>&rsquo;, we can emulate the
1286+
functionality of HTML's <code>&lt;center></code> element:</p>
14021287

14031288
<pre>&lt;div>
1404-
&lt;span>foo foo foo foo&lt;/span>
1405-
&lt;span>bar bar&lt;br>bar bar&lt;/span>
1406-
&lt;span>foo foo foo foo foo foo foo foo foo foo foo foo&lt;/span>
1289+
&lt;div>foo foo foo foo&lt;/div>
1290+
&lt;div>bar bar&lt;br>bar bar&lt;/div>
1291+
&lt;div>foo foo foo foo foo foo foo foo foo foo foo foo&lt;/div>
14071292
&lt;/div>
14081293
&lt;style>
14091294
div {
14101295
display: flexbox;
1411-
flex-direction: tb;
1296+
flex-flow: column;
14121297
width: 200px;
14131298
}
1414-
span {/* /* */ */
1415-
margin: 0 auto;
1299+
div > div {
1300+
flex-align: center;
14161301
}
14171302
&lt;/style></pre>
14181303

14191304
<p><img alt="" src="images/basic-vertical-flexbox.png"></p>
14201305
</div>
14211306

1422-
<p class=issue>TODO: examples, with pictures
1307+
<p class=issue>More examples for the other alignment values!
14231308

1424-
<p class=issue>TODO: alignment rules should be compatible with
1425-
css3-grid-layout, if possible
1309+
<p>The precise effects of this property are articulated in the <a
1310+
href="#layout-algorithm">Layout Algorithm</a> section.
14261311

14271312
<h2 id=multiline><span class=secno>6. </span> Multi-line flexbox</h2>
14281313

@@ -2229,7 +2114,7 @@ <h2 class=no-num id=property>Property index</h2>
22292114
<tr>
22302115
<th><a class=property href="#flex-align0">flex-align</a>
22312116

2232-
<td>before | after | middle | stretch | baseline
2117+
<td>start | end | center | baseline | stretch
22332118

22342119
<td>stretch
22352120

@@ -2343,6 +2228,9 @@ <h2 class=no-num id=index>Index</h2>
23432228
<li>cross size, <a href="#cross-size" title="cross
23442229
size"><strong>2.</strong></a>
23452230

2231+
<li>cross size property, <a href="#cross-size-property" title="cross size
2232+
property"><strong>2.</strong></a>
2233+
23462234
<li>cross-start, <a href="#cross-start"
23472235
title=cross-start><strong>2.</strong></a>
23482236

@@ -2428,6 +2316,9 @@ <h2 class=no-num id=index>Index</h2>
24282316
<li>main size, <a href="#main-size" title="main
24292317
size"><strong>2.</strong></a>
24302318

2319+
<li>main size property, <a href="#main-size-property" title="main size
2320+
property"><strong>2.</strong></a>
2321+
24312322
<li>main-start, <a href="#main-start"
24322323
title=main-start><strong>2.</strong></a>
24332324

0 commit comments

Comments
 (0)