Skip to content

Commit 446ae5c

Browse files
committed
[css-grid-1][editorial] Rearrange the grid layout algo a little for clarity, making a new top-level algo. #3418
1 parent 04f87ed commit 446ae5c

File tree

2 files changed

+109
-55
lines changed

2 files changed

+109
-55
lines changed

css-grid-1/Overview.bs

+46-20
Original file line numberDiff line numberDiff line change
@@ -3540,7 +3540,7 @@ Gutters: the 'row-gap', 'column-gap', and 'gap' properties</h3>
35403540

35413541
Note: Additional spacing may be added between tracks
35423542
due to 'justify-content'/'align-content'.
3543-
See [[#algo-overview]].
3543+
See [[#algo-grid-sizing]].
35443544
This space effectively increases the size of the <a>gutters</a>.
35453545

35463546
If a <a>grid</a> is <a>fragmented</a> between tracks,
@@ -3773,10 +3773,44 @@ Grid Container Baselines</h3>
37733773
██████ ████ ████████ ████ ██ ██ ██████
37743774
-->
37753775

3776-
<h2 id='layout-algorithm'>
3777-
Grid Sizing</h2>
3776+
<h2 id='layout-algorithm' oldids="algo-overview" dfn export>
3777+
Grid Layout Algorithm</h2>
37783778

3779-
This section defines the <dfn export>grid sizing algorithm</dfn>,
3779+
This section defines the <b>grid layout algorithm</b>,
3780+
which sizes the [=grid container=],
3781+
sizes and positions all the [=grid tracks=],
3782+
and lays out the [=grid items=]
3783+
which have been [=grid item placement algorithm|placed=] into its [=grid areas=].
3784+
3785+
1. First, find the size of the [=grid container=],
3786+
per [[#intrinsic-sizes]].
3787+
3788+
Note: During this phase,
3789+
cyclic <<percentage>>s in track sizes are treated as ''grid-template-columns/auto''.
3790+
3791+
2. Given the resulting [=grid container=] size,
3792+
run the [=Grid Sizing Algorithm=]
3793+
to size the [=grid=].
3794+
3795+
Note: During this phase,
3796+
<<percentage>>s in track sizes are resolved
3797+
against the [=grid container=] size.
3798+
3799+
3. Lay out the [=grid items=] into their respective containing blocks.
3800+
Each [=grid area's=] width and height
3801+
are considered [=definite=] for this purpose.
3802+
3803+
Note: Since formulas calculated using only definite sizes,
3804+
such as the [=stretch fit=] formula,
3805+
are also definite,
3806+
the size of a grid item which is stretched
3807+
is also considered definite.
3808+
3809+
3810+
<h3 id="algo-grid-sizing" dfn export>
3811+
Grid Sizing Algorithm</h3>
3812+
3813+
This section defines the <b>grid sizing algorithm</b>,
37803814
which determines the size of all <a>grid tracks</a>
37813815
and, by extension, the entire grid.
37823816

@@ -3793,9 +3827,6 @@ Grid Sizing</h2>
37933827

37943828
The <a>grid sizing algorithm</a> defines how to resolve these sizing constraints into used track sizes.
37953829

3796-
<h3 id="algo-overview">
3797-
Grid Sizing Algorithm</h3>
3798-
37993830
<ol>
38003831
<li>
38013832
First, the <a>track sizing algorithm</a> is used to resolve the sizes of the <a>grid columns</a>.
@@ -3889,26 +3920,14 @@ Grid Sizing Algorithm</h3>
38893920
to account for the effective column gap sizes.
38903921

38913922
<li>
3892-
Finally, the <a>grid container</a> is sized
3893-
using the resulting size of the <a>grid</a> as its content size,
3894-
and the tracks are aligned within the <a>grid container</a>
3923+
Finally, align the tracks within the <a>grid container</a>
38953924
according to the 'align-content' and 'justify-content' properties.
38963925

38973926
Note: This can introduce extra space between tracks,
38983927
potentially enlarging the grid area of any grid items spanning the gaps
38993928
beyond the space allotted to during track sizing.
39003929
</ol>
39013930

3902-
Once the size of each <a>grid area</a> is thus established,
3903-
the <a>grid items</a> are laid out into their respective containing blocks.
3904-
The <a>grid area’s</a> width and height are considered <a>definite</a> for this purpose.
3905-
3906-
Note: Since formulas calculated using only definite sizes,
3907-
such as the <a>stretch fit</a> formula,
3908-
are also definite,
3909-
the size of a grid item which is stretched
3910-
is also considered definite.
3911-
39123931
<h3 id='algo-terms'>
39133932
Track Sizing Terminology</h3>
39143933

@@ -4887,6 +4906,13 @@ Changes since the <a href="https://www.w3.org/TR/2020/CRD-css-grid-1-20201218/">
48874906
instead use the <a>grid area</a> determined in [[#abspos-items]].</del>
48884907
</blockquote>
48894908

4909+
<li id="change-2020-rearrange-layout-algo">
4910+
Rearranged the Grid Sizing Algorithm overview
4911+
to better convey the relationship
4912+
between grid container sizing
4913+
and grid track sizing.
4914+
See [[#layout-algorithm]].
4915+
(<a href="https://github.com/w3c/csswg-drafts/issues/3418">Issue 3418</a>)
48904916
</ul>
48914917

48924918
<h3 id="changes-202008">

css-grid-2/Overview.bs

+63-35
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,7 @@ Gutters: the 'row-gap', 'column-gap', and 'gap' properties</h3>
40924092

40934093
Note: Additional spacing may be added between tracks
40944094
due to 'justify-content'/'align-content'.
4095-
See [[#algo-overview]].
4095+
See [[#algo-grid-sizing]].
40964096
This space effectively increases the size of the <a>gutters</a>.
40974097

40984098
If a <a>grid</a> is <a>fragmented</a> between tracks,
@@ -4325,10 +4325,48 @@ Grid Container Baselines</h3>
43254325
██████ ████ ████████ ████ ██ ██ ██████
43264326
-->
43274327

4328-
<h2 id='layout-algorithm'>
4329-
Grid Sizing</h2>
4328+
<h2 id='layout-algorithm' oldids="algo-overview" dfn export>
4329+
Grid Layout Algorithm</h2>
43304330

4331-
This section defines the <dfn export>grid sizing algorithm</dfn>,
4331+
This section defines the <b>grid layout algorithm</b>,
4332+
which sizes the [=grid container=],
4333+
sizes and positions all the [=grid tracks=],
4334+
and lays out the [=grid items=]
4335+
which have been [=grid item placement algorithm|placed=] into its [=grid areas=].
4336+
4337+
1. First, find the size of the [=grid container=],
4338+
per [[#intrinsic-sizes]].
4339+
4340+
Note: During this phase,
4341+
cyclic <<percentage>>s in track sizes are treated as ''grid-template-columns/auto''.
4342+
4343+
2. Given the resulting [=grid container=] size,
4344+
run the [=Grid Sizing Algorithm=]
4345+
to size the [=grid=].
4346+
4347+
Note: During this phase,
4348+
<<percentage>>s in track sizes are resolved
4349+
against the [=grid container=] size.
4350+
4351+
3. Lay out the [=grid items=] into their respective containing blocks.
4352+
Each [=grid area's=] width and height
4353+
are considered [=definite=] for this purpose.
4354+
4355+
Note: Since formulas calculated using only definite sizes,
4356+
such as the [=stretch fit=] formula,
4357+
are also definite,
4358+
the size of a grid item which is stretched
4359+
is also considered definite.
4360+
4361+
Note: Placement of all [=grid items=],
4362+
including [=subgrids=] and their sub-items,
4363+
occurs before sizing.
4364+
4365+
4366+
<h3 id="algo-grid-sizing" dfn export>
4367+
Grid Sizing Algorithm</h3>
4368+
4369+
This section defines the <b>grid sizing algorithm</b>,
43324370
which determines the size of all <a>grid tracks</a>
43334371
and, by extension, the entire grid.
43344372

@@ -4345,13 +4383,6 @@ Grid Sizing</h2>
43454383

43464384
The <a>grid sizing algorithm</a> defines how to resolve these sizing constraints into used track sizes.
43474385

4348-
<h3 id="algo-overview">
4349-
Grid Sizing Algorithm</h3>
4350-
4351-
Note: Placement of all [=grid items=],
4352-
including [=subgrids=] and their sub-items,
4353-
occurs before sizing.
4354-
43554386
<ol>
43564387
<li>
43574388
First, the <a>track sizing algorithm</a> is used to resolve the sizes of the <a>grid columns</a>.
@@ -4462,9 +4493,7 @@ Grid Sizing Algorithm</h3>
44624493
to account for the effective column gap sizes.
44634494

44644495
<li>
4465-
Finally, the <a>grid container</a> is sized
4466-
using the resulting size of the <a>grid</a> as its content size,
4467-
and the tracks are aligned within the <a>grid container</a>
4496+
Finally, align the tracks within the <a>grid container</a>
44684497
according to the 'align-content' and 'justify-content' properties.
44694498

44704499
Note: This can introduce extra space between tracks,
@@ -4481,16 +4510,6 @@ Grid Sizing Algorithm</h3>
44814510
Note this means that a [=subgrid=] establishing an [=orthogonal flow=]
44824511
would have the order of its track sizing inverted compared to a nested grid.
44834512

4484-
Once the size of each <a>grid area</a> is thus established,
4485-
the <a>grid items</a> are laid out into their respective containing blocks.
4486-
The <a>grid area’s</a> width and height are considered <a>definite</a> for this purpose.
4487-
4488-
Note: Since formulas calculated using only definite sizes,
4489-
such as the <a>stretch fit</a> formula,
4490-
are also definite,
4491-
the size of a grid item which is stretched
4492-
is also considered definite.
4493-
44944513
<div class="example">
44954514
The following example illustrates how per-axis subgrids are sized:
44964515

@@ -5391,17 +5410,18 @@ Changes</h2>
53915410
Changes since the <a href="https://www.w3.org/TR/2020/CRD-css-grid-2-20201218/">18 December 2020 CR</a></h3>
53925411

53935412
<ul class="non-normative">
5394-
Clarified how [=relative positioning=] applies to [=subgrids=].
5395-
(<a href="https://github.com/w3c/csswg-drafts/issues/7123">Issue 7123</a>)
5396-
<blockquote>
5397-
<ul>
5398-
<li>
5399-
<ins>[=Relative positioning=] applies to <a>subgrids</a> as normal,
5400-
and shifts the box and its content together as usual.
5401-
(Note: Relative positioning takes place after alignment,
5402-
and does not affect track sizing.)</ins>
5403-
</ul>
5404-
</blockquote>
5413+
<li>
5414+
Clarified how [=relative positioning=] applies to [=subgrids=].
5415+
(<a href="https://github.com/w3c/csswg-drafts/issues/7123">Issue 7123</a>)
5416+
<blockquote>
5417+
<ul>
5418+
<li>
5419+
<ins>[=Relative positioning=] applies to <a>subgrids</a> as normal,
5420+
and shifts the box and its content together as usual.
5421+
(Note: Relative positioning takes place after alignment,
5422+
and does not affect track sizing.)</ins>
5423+
</ul>
5424+
</blockquote>
54055425

54065426
<li id="change-2020-flex-intrinsic-ratios">
54075427
Changed intrinsic track space distribution <a href="#algo-spanning-flex-items">across flexible tracks</a>
@@ -5499,6 +5519,14 @@ Changes since the <a href="https://www.w3.org/TR/2020/CRD-css-grid-2-20201218/">
54995519
<del>However, if the <a>grid container</a> parent is also the generator of the absolutely positioned element's <a>containing block</a>,
55005520
instead use the <a>grid area</a> determined in [[#abspos-items]].</del>
55015521
</blockquote>
5522+
5523+
<li id="change-2020-rearrange-layout-algo">
5524+
Rearranged the Grid Sizing Algorithm overview
5525+
to better convey the relationship
5526+
between grid container sizing
5527+
and grid track sizing.
5528+
See [[#layout-algorithm]].
5529+
(<a href="https://github.com/w3c/csswg-drafts/issues/3418">Issue 3418</a>)
55025530
</ul>
55035531

55045532
<h3 id="changes-202008">

0 commit comments

Comments
 (0)