|
9 | 9 | <link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet |
10 | 10 | type="text/css"> |
11 | 11 |
|
| 12 | + <style> |
| 13 | + code.one-line { white-space: pre; } |
| 14 | + </style> |
| 15 | + |
12 | 16 | <body> |
13 | 17 | <div class=head> <!--begin-logo--> |
14 | 18 | <p><a href="http://www.w3.org/"><img alt=W3C height=48 |
15 | 19 | src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo--> |
16 | 20 |
|
17 | 21 | <h1 id=head-box-flexible>CSS Flexible Box Layout Module</h1> |
18 | 22 |
|
19 | | - <h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 24 November 2011</h2> |
| 23 | + <h2 class="no-num no-toc" id=w3c-working>Editor's Draft, 7 December 2011</h2> |
20 | 24 |
|
21 | 25 | <dl> |
22 | 26 | <dt>This version: |
| 27 | + <!--<dd><a href="http://www.w3.org/TR/2011/ED-css3-flexbox-20111207/">http://www.w3.org/TR/2011/ED-css3-flexbox-20111207/</a>--> |
| 28 | + |
23 | 29 |
|
24 | | - <dd><!-- <a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20111124/">http://www.w3.org/TR/2011/WD-css3-flexbox-20111124/</a></dd> --> |
25 | | - <a |
| 30 | + <dd><a |
26 | 31 | href="http://dev.w3.org/csswg/css3-flexbox/">http://dev.w3.org/csswg/css3-flexbox/</a> |
27 | 32 |
|
28 | 33 |
|
29 | 34 | <dt>Latest version: |
| 35 | + <!--<dd><a href="http://www.w3.org/TR/css3-flexbox/">http://www.w3.org/TR/css3-flexbox/</a>--> |
| 36 | + |
30 | 37 |
|
31 | 38 | <dd><a |
32 | 39 | href="http://www.w3.org/TR/css3-flexbox/">http://www.w3.org/TR/css3-flexbox/</a> |
@@ -1410,6 +1417,157 @@ <h2 id=layout-algorithm><span class=secno>7. </span> Flexbox Layout |
1410 | 1417 | calculations that depend on those lengths.</p> |
1411 | 1418 | </div> |
1412 | 1419 |
|
| 1420 | + <p>The layout algorithm for flexbox is, unfortunately, too complex and |
| 1421 | + interdependent to usefully describe in pieces within each property's |
| 1422 | + description. As such, the normative layout algorithm is described in this |
| 1423 | + chapter. Note that this is the <em>definitive</em> description of the |
| 1424 | + flexbox layout algorithm - any information located elsewhere in this spec |
| 1425 | + is informative only. Note as well that only the <strong>output</strong> of |
| 1426 | + the algorithm is normative. The precise steps described in this section |
| 1427 | + are informative, and written with an eye toward clarity and simplicity, |
| 1428 | + not efficiency. Any algorithm that achieves the same results is |
| 1429 | + acceptable. |
| 1430 | + |
| 1431 | + <p>This section is mainly intended for implementors. Authors writing web |
| 1432 | + pages should generally be served well by the individual property |
| 1433 | + descriptions, and do not need to read this section unless they have a |
| 1434 | + deep-seated urge to understand arcane details of CSS layout. |
| 1435 | + |
| 1436 | + <p>To lay out a flexbox and its contents, follow these steps: |
| 1437 | + |
| 1438 | + <ol> |
| 1439 | + <li>Re-order the flexbox items according to their ‘<a |
| 1440 | + href="#flex-order0"><code class=property>flex-order</code></a>’. |
| 1441 | + The items with the lowest (most negative) ‘<a |
| 1442 | + href="#flex-order0"><code class=property>flex-order</code></a>’ |
| 1443 | + values are first in the ordering. If multiple items share a ‘<a |
| 1444 | + href="#flex-order0"><code class=property>flex-order</code></a>’ |
| 1445 | + value, they're ordered by document order. This affects the order in which |
| 1446 | + the flexbox items generate boxes in the box-tree, and how the rest of |
| 1447 | + this algorithm deals with the items. |
| 1448 | + |
| 1449 | + <li> |
| 1450 | + <p>Find the hypothetical size of each flexbox item. For the purpose of |
| 1451 | + this step:</p> |
| 1452 | + |
| 1453 | + <ul> |
| 1454 | + <li>Treat the flexbox as ‘<code |
| 1455 | + class=css>display:block</code>’ if it was ‘<code |
| 1456 | + class=css>display:flexbox</code>’, and as ‘<code |
| 1457 | + class=css>display:inline-block</code>’ if it was ‘<code |
| 1458 | + class=css>display:inline-flexbox</code>’. |
| 1459 | + |
| 1460 | + <li>Treat the flexbox and every flexbox item as establishing a block |
| 1461 | + formatting context. |
| 1462 | + |
| 1463 | + <li>If the width or height of a flexbox item is flexible, treat it as |
| 1464 | + the preferred width of the flexible length. <strong>Do not apply |
| 1465 | + min/max-width/height constraints to the preferred widths/heights of |
| 1466 | + flexible lengths - those constraints are handled elsewhere in this |
| 1467 | + algorithm, and doing so will produce incorrect results.</strong> Do |
| 1468 | + apply those constraints to non-flexible lengths, as normal. |
| 1469 | + |
| 1470 | + <li>If the width or height of a flexbox item is ‘<code |
| 1471 | + class=property>auto</code>’, or is being treated as ‘<code |
| 1472 | + class=property>auto</code>’ due to the above step, treat it as |
| 1473 | + ‘<code class=property>fit-content</code>’. <span |
| 1474 | + class=note>IIRC, this is the name we expect to give to the "shrinkwrap" |
| 1475 | + behavior.</span>. |
| 1476 | + </ul> |
| 1477 | + |
| 1478 | + <p>For each flexbox item:</p> |
| 1479 | + |
| 1480 | + <ol> |
| 1481 | + <li>Ignore all other flexbox items. The rest of this sub-algorithm is |
| 1482 | + run with the assumption that the flexbox contains only the single |
| 1483 | + flexbox item in question. |
| 1484 | + |
| 1485 | + <li>Using normal block layout, resolve the width and height of the |
| 1486 | + flexbox item. |
| 1487 | + </ol> |
| 1488 | + |
| 1489 | + <p>Each flexbox item now has a hypothetical width and hypothetical |
| 1490 | + height.</p> |
| 1491 | + |
| 1492 | + <li>Find the available space of the flexbox (the space inside the flexbox |
| 1493 | + that can be used to lay out children). Basically, how wide would a block |
| 1494 | + be in that situation with "width:fill" (or "auto", in normal block |
| 1495 | + layout), minus margin/border/padding. <span class=issue>Figure this out |
| 1496 | + by talking with Ojan, etc.</span> |
| 1497 | + |
| 1498 | + <li> |
| 1499 | + <p>If the flexbox is multiline, group the flexbox items into multiple |
| 1500 | + lines:</p> |
| 1501 | + |
| 1502 | + <ol> |
| 1503 | + <li>Collect as many consecutive flexbox items as possible, starting from |
| 1504 | + the first item, while keeping the sum of their main size smaller than |
| 1505 | + the flexbox's available space. The items so collected form a single |
| 1506 | + flexbox line. |
| 1507 | + |
| 1508 | + <li>Repeat the previous step, starting each time from the first flexbox |
| 1509 | + item not yet collected into a flexbox line, until all flexbox items |
| 1510 | + have been collected into flexbox lines. |
| 1511 | + </ol> |
| 1512 | + |
| 1513 | + <p>If the flexbox is single-line, collect all the flexbox items into a |
| 1514 | + single flexbox line.</p> |
| 1515 | + |
| 1516 | + <li> |
| 1517 | + <p>Find the actual main size of the flexbox.</p> |
| 1518 | + |
| 1519 | + <p>If the flexbox is to be shrinkwrapped in the main axis, then, for each |
| 1520 | + flexbox line, sum the hypothetical main sizes of the items in the line. |
| 1521 | + The actual main size of the flexbox is then the largest of these sums.</p> |
| 1522 | + |
| 1523 | + <p>Otherwise, determine the size as normal for block layout.</p> |
| 1524 | + |
| 1525 | + <li>For each flexbox line, <a |
| 1526 | + href="#resolve-the-flexible-lengths"><i>resolve the flexible |
| 1527 | + lengths</i></a> of the items contained within it. |
| 1528 | + </ol> |
| 1529 | + |
| 1530 | + <p> ... |
| 1531 | + |
| 1532 | + <p>To <dfn id=resolve-the-flexible-lengths>resolve the flexible |
| 1533 | + lengths</dfn> of the items within a flexbox line: |
| 1534 | + |
| 1535 | + <ol> |
| 1536 | + <li><a href="#distribute-the-free-space"><i>Distribute the free |
| 1537 | + space</i></a> in the flexbox line. If any flexbox item's main size is in |
| 1538 | + violation of its max size constraint (‘<code |
| 1539 | + class=property>max-height</code>’ or ‘<code |
| 1540 | + class=property>max-width</code>’), mark the item as being in |
| 1541 | + violation of a max size constraint; if any other item is marked as being |
| 1542 | + in violation of a max size constraint from a previous invocation of this |
| 1543 | + step, remove the mark. Set its main size to be equal to its max size |
| 1544 | + constraint. <a href="#distribute-the-free-space"><i>Distribute the free |
| 1545 | + space</i></a> again. |
| 1546 | + |
| 1547 | + <li><a href="#distribute-the-free-space"><i>Distribute the free |
| 1548 | + space</i></a> in the flexbox line. If any flexbox item's main size is in |
| 1549 | + violation of its min size constraint (‘<code |
| 1550 | + class=property>min-height</code>’ or ‘<code |
| 1551 | + class=property>min-width</code>’), mark the item as being in |
| 1552 | + violation of a min size constraint; if any other item is marked as being |
| 1553 | + in violation of a min size constraint from a previous invocation of this |
| 1554 | + step, remove the mark. Set its main size to be equal to its min size |
| 1555 | + constraint. <a href="#distribute-the-free-space"><i>Distribute the free |
| 1556 | + space</i></a> again. |
| 1557 | + |
| 1558 | + <li>If the set of flexbox items in the line that are marked as violating a |
| 1559 | + max or min size constraint has changed since the last time this step was |
| 1560 | + reached, or this is the first time this step was reached, restart this |
| 1561 | + algorithm. |
| 1562 | + </ol> |
| 1563 | + |
| 1564 | + <p>To <dfn id=distribute-the-free-space>distribute the free space</dfn> in |
| 1565 | + a flexbox line: |
| 1566 | + |
| 1567 | + <ol> |
| 1568 | + <li>... |
| 1569 | + </ol> |
| 1570 | + |
1413 | 1571 | <h2 id=pagination><span class=secno>8. </span> Page breaks in flexbox</h2> |
1414 | 1572 |
|
1415 | 1573 | <p class=issue>TODO: define how flexbox should break on pages, columns, |
@@ -1626,6 +1784,9 @@ <h2 class=no-num id=index>Index</h2> |
1626 | 1784 | <li>cross-start, <a href="#cross-start" |
1627 | 1785 | title=cross-start><strong>2.</strong></a> |
1628 | 1786 |
|
| 1787 | + <li>distribute the free space, <a href="#distribute-the-free-space" |
| 1788 | + title="distribute the free space"><strong>7.</strong></a> |
| 1789 | + |
1629 | 1790 | <li>end, <a href="#flex-align-end" title=end><strong>5.2.</strong></a>, <a |
1630 | 1791 | href="#flex-line-pack-end" title=end><strong>6.1.</strong></a>, <a |
1631 | 1792 | href="#flex-pack-end" title=end><strong>5.1.</strong></a> |
@@ -1700,6 +1861,9 @@ <h2 class=no-num id=index>Index</h2> |
1700 | 1861 | <li>preferred size, <a href="#preferred-size" |
1701 | 1862 | title="preferred size"><strong>4.1.</strong></a> |
1702 | 1863 |
|
| 1864 | + <li>resolve the flexible lengths, <a href="#resolve-the-flexible-lengths" |
| 1865 | + title="resolve the flexible lengths"><strong>7.</strong></a> |
| 1866 | + |
1703 | 1867 | <li>row, <a href="#flex-flow-row" title=row><strong>3.1.</strong></a> |
1704 | 1868 |
|
1705 | 1869 | <li>row-reverse, <a href="#flex-flow-row-reverse" |
|
0 commit comments