You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: css3-grid-align/Overview.html
+184-3Lines changed: 184 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,11 @@ <h2 class="introductory">Table of Contents</h2>
153
153
<liclass="tocline"><aclass="tocxref" href="#defining-default-size-for-implicit-columns-and-rows"><spanclass="secno">7.5.1 </span>Defining a Default Size for Implicit Columns and Rows</a></li>
154
154
</ul>
155
155
</li>
156
+
<liclass="tocline"><aclass="tocxref" href="#automatic-placement-of-grid-items"><spanclass="secno">7.6 </span>Automatic Placement of Grid Items</a>
<h3><spanclass="secno">7.6</span> Automatic Placement of Grid Items</h3>
1420
+
<pclass="note">
1421
+
This section describes early thinking around automatic placement of Grid Items. Multiple algorithms are possible for such a feature.
1422
+
One is proposed here.
1423
+
</p>
1424
+
<p>
1425
+
<ahref="#grid-item">Grid Item</a>s can be automatically placed into an unoccupied space of the Grid.
1426
+
The grid-flow property controls the direction in which the search for unoccupied space takes place, and whether rows or columns are added as needed to accomodate the content.
1427
+
Note that <ahref="#grid-cell">Grid Cell</a>s cannot be automatically placed.
1428
+
</p>
1429
+
<p>
1430
+
A grid-flow value of 'rows' will search across columns and then rows for unoccupied space, and will create additional rows
1431
+
as needed to accomodate content. Similarly, a grid-flow value of 'columns' searches rows first and creates additional
1432
+
columns as needed until sufficient space is found.
1433
+
</p>
1434
+
<tableid="grid-flow-property" class="propdef">
1435
+
<tbody>
1436
+
<tr>
1437
+
<td>Name:</td>
1438
+
<td><dfnid="grid-flow">grid-flow</dfn></td>
1439
+
</tr>
1440
+
<tr>
1441
+
<td>Value:</td>
1442
+
<td>'none' | 'rows' | 'columns'</td>
1443
+
</tr>
1444
+
<tr>
1445
+
<td>Initial:</td>
1446
+
<td>none</td>
1447
+
</tr>
1448
+
<tr>
1449
+
<td>Applies to:</td>
1450
+
<td>Grid elements</td>
1451
+
</tr>
1452
+
<tr>
1453
+
<td>Inherited:</td>
1454
+
<td>no</td>
1455
+
</tr>
1456
+
<tr>
1457
+
<td>Percentages:</td>
1458
+
<td>n/a</td>
1459
+
</tr>
1460
+
<tr>
1461
+
<td>Media:</td>
1462
+
<td>visual, paged</td>
1463
+
</tr>
1464
+
<tr>
1465
+
<td>Computed value:</td>
1466
+
<td>specified value</td>
1467
+
</tr>
1468
+
</tbody>
1469
+
</table>
1470
+
<divclass="sidefigure">
1471
+
<p>
1472
+
<imgalt="Image: A form arranged using automatic placement." src="files/auto-placed-form.png" />
1473
+
</p>
1474
+
<pclass="caption">A form arranged using automatic placement.</p>
1475
+
</div>
1476
+
<p>
1477
+
The search for unoccupied space is conducted one <ahref="#grid-item">Grid Item</a> at a time.
1478
+
First <ahref="#grid-item">Grid Item</a>s which have a constraint on either their grid-row or grid-column are placed, followed by
1479
+
<ahref="#grid-item">Grid Item</a>s which have both a grid-row and grid-column value of 'auto'.
1480
+
If grid-flow is 'rows', <ahref="#grid-item">Grid Item</a>s having an auto value for grid-row are placed before those with
1481
+
an auto value for grid-column. The reverse is true when grid-flow is 'columns'.
1482
+
</p>
1483
+
<p>
1484
+
In the following example, there are three columns, each auto-sized to their contents.
1485
+
No rows are explicitly defined. The grid-flow property is 'rows' which instructs the grid
1486
+
to search across its three columns starting with the first row, then the next, adding rows
1487
+
as needed until sufficient space is located to accomodate the position of any auto-placed
1488
+
<ahref="#grid-item">Grid Item</a>.
1489
+
Figure 11 illustrates the result.
1490
+
</p>
1491
+
<preclass="example"><style type="text/css">
1492
+
form {
1493
+
display: grid;
1494
+
grid-columns: "labels" auto "controls" auto "oversized" auto;
1495
+
grid-flow: rows
1496
+
}
1497
+
form > input, form > select {
1498
+
/* Place all controls in the "controls" column and automatically find the next available row. */
1499
+
grid-column: "controls";
1500
+
grid-row: auto
1501
+
}
1502
+
form > label {
1503
+
/* Ensure that label is a valid grid item by setting its display to 'block'. */
1504
+
display: block;
1505
+
1506
+
/* Place all labels in the "labels" column and automatically find the next available row. */
1507
+
grid-column: "labels";
1508
+
grid-row: auto
1509
+
}
1510
+
1511
+
#department {
1512
+
/* Auto place this item in the "oversized" column in the first row where a cell that spans three rows */
1513
+
/* won't overlap other explicitly placed items or cells or any items automatically placed prior to */
1514
+
/* this cell. */
1515
+
grid-column: "oversized";
1516
+
grid-row: auto;
1517
+
grid-row-span: 3;
1518
+
}
1519
+
1520
+
/* Place all the buttons of the form in the explicitly defined grid cell. */
1521
+
#buttons {
1522
+
grid-row: auto;
1523
+
1524
+
/* Ensure the button cell spans the entire grid element in the column direction. */
The following summarizes the algorithm for auto placement of Grid Items. For each Grid Item in source order:
1568
+
</p>
1569
+
<ol>
1570
+
<li>If both grid-row and grid-column are not 'auto' the Grid Item is placed as specified:
1571
+
<ol>
1572
+
<li>If grid-row is not auto, the Grid Item is placed between the starting and ending lines specified by the grid-row property. An implicit Grid Line number is assigned as the starting line for grid-column such that the Grid Item does not overlap Grid Items already placed in the Grid. If necessary, new column Grid Lines are created to satisfy this constraint.</li>
1573
+
<li>If grid-column is not auto, the Grid Item is placed between the starting and ending lines specified by the grid-column property. An implicit Grid Line number is assigned as the starting line for grid-row such that the Grid Item does not overlap Grid Items already placed in the Grid. If necessary, new row Grid Lines are created to satisfy this constraint.</li>
1574
+
</ol>
1575
+
</li>
1576
+
<li>Otherwise when both grid-column and grid-row are 'auto', beginning with the implicit Grid Line numbers of the previously placed Grid Item, or (1, 1) if this is the first Grid Item to be automatically placed:
1577
+
<ol>
1578
+
<li>Place the Grid Item in the Grid Cell currently defined by the grid-row and grid-column auto position if not already occupied by another Grid Item.</li>
1579
+
<li>Otherwise:
1580
+
<ol>
1581
+
<li>If grid-flow is 'rows', increment the grid-column. If the grid-column value is outside of bounds of the grid (as defined at this point, explicitly or by previously placed items), set grid-column to one and increment grid-row (creating new row Grid Lines as needed).</li>
1582
+
<li>If grid-flow is 'columns', increment grid-row. If the grid-row value is outside of bounds of the grid (as defined at this point, explicitly or by previously placed items), set grid-row to one and increment grid-column (creating new column Grid Lines as needed).</li>
and for the definitions of inline direction and block flow direction. [<cite><ahref="#bib-CSS3WRITINGMODES" rel="biblioentry" class="bibref">CSS3WRITINGMODES</a></cite>]
1454
1635
</p>
1455
1636
<p>
1456
-
Figures 11, 12, and 13 illustrate the placement and orientation of the <ahref="#grid-element">Grid element's</a> rows, columns, and
1637
+
Figures 12, 13, and 14 illustrate the placement and orientation of the <ahref="#grid-element">Grid element's</a> rows, columns, and
1457
1638
<ahref="#grid-item">Grid Item</a>s using different writing modes on the <ahref="#grid-element">Grid element</a>.
1458
1639
In each of the figures, the markup shown in the following example is used to place <ahref="#grid-item">Grid Item</a> A in column 1, row 1, and <ahref="#grid-item">Grid Item</a> B in column 2, row 2.
1459
1640
<ahref="#grid-item">Grid Item</a> A is aligned in each figure to the starting edges of its row and column.
@@ -1604,7 +1785,7 @@ <h2><span class="secno">9. </span>Drawing Order of Grid Items</h2>
1604
1785
In cases where <ahref="#grid-item">Grid Item</a>s occupy the same <ahref="#grid-layer">grid-layer</a>, source order determines which item will be drawn first.
1605
1786
</p>
1606
1787
<p>
1607
-
Figure 14 illustrates the drawing order of the markup shown in the following example.
1788
+
Figure 15 illustrates the drawing order of the markup shown in the following example.
0 commit comments