Skip to content

Commit 10aa992

Browse files
committed
[css-grid] Make grid items maintain intrinsic ratio in default case per #523. (First cut, needs review, didn't address object-fit question.)
1 parent ab939be commit 10aa992

1 file changed

Lines changed: 49 additions & 31 deletions

File tree

css-grid/Overview.bs

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,17 +1063,55 @@ Grid Items</h2>
10631063
<h3 id="grid-item-sizing">
10641064
Grid Item Sizing</h3>
10651065

1066-
A <a>grid item</a> is sized within the containing block defined by its <a>grid area</a>
1067-
using the 'width' calculation rules for non-replaced block boxes
1068-
as defined in <a href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">CSS2.1 &sect; 10.3.3</a>
1069-
(meaning ''width/auto'' values in either axis are
1070-
effectively sized to fill the remaining space).
1066+
A <a>grid item</a> is sized within the containing block defined by its <a>grid area</a>.
1067+
1068+
Items without an intrinsic ratio use, in both axes,
1069+
the 'width' calculation rules for non-replaced block boxes
1070+
as defined in <a href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">CSS2.1 &sect; 10.3.3</a>.
1071+
(Meaning, ''width/auto'' values in either axis are
1072+
effectively sized to fill the remaining space.)
10711073
However, the <a>box alignment properties</a> have special effects:
10721074
when 'align-self'/'justify-self' is neither ''justify-self/normal'' nor ''justify-self/stretch'',
10731075
an ''width/auto'' size for the <a>grid item</a> in that axis
10741076
is treated as ''width/fit-content'' instead of as the <a>fill-available size</a>.
10751077
See [[#alignment]].
10761078

1079+
Items with an intrinsic ratio follow the same rules,
1080+
except that in the case of a ''align-self/normal'' alignment value,
1081+
an ''width/auto'' size for the <a>grid item</a>
1082+
is further reduced or increased in that axis
1083+
(while maintaining any specified minimum or maximum size)
1084+
if necessary to maintain the intrinsic aspect ratio.
1085+
If both axes have ''align-self/normal'' alignment and ''width/auto'' sizing,
1086+
then this adjustment is made in the axis that needs reduction.
1087+
1088+
<div class="note">
1089+
The following informative table summarizes the automatic sizing of grid items:
1090+
1091+
<table class=data>
1092+
<caption>Summary of automatic sizing behavior of grid items</caption>
1093+
<thead>
1094+
<tr>
1095+
<th>Alignment
1096+
<th>Non-replaced Element Size
1097+
<th>Replaced Element Size
1098+
<tbody>
1099+
<tr>
1100+
<th scope=row>''align-self/normal''
1101+
<td>Fill grid area
1102+
<td>''object-fit/contain''-type sizing into grid area
1103+
<tr>
1104+
<th scope=row>''align-self/stretch''
1105+
<td>Fill grid area
1106+
<td>Fill grid area
1107+
<tr>
1108+
<th scope=row>''align-self/start''/''align-self/center''/etc.
1109+
<td>''width/fit-content'' sizing (like floats)
1110+
<td>Use intrinsic size
1111+
</table>
1112+
</div>
1113+
1114+
10771115
Note: The ''min-width/auto'' value of 'min-width' and 'min-height'
10781116
affects track sizing in the relevant axis
10791117
similar to how it affects the main size of a <a>flex item</a>.
@@ -4268,35 +4306,15 @@ Acknowledgements</h2>
42684306
<h2 class="no-num" id="changes">
42694307
Changes</h2>
42704308

4271-
Changes since the <a href="https://www.w3.org/TR/2016/WD-css-grid-1-20160519/">19 May 2016 Working Draft</a> are:
4272-
4309+
Changes since the <a href="https://www.w3.org/TR/2016/CR-css-grid-1-20160929/">29 September 2016 Candidate Recommendation</a> are:
42734310
<ul>
4274-
<li>Disallowed ''repeat()'' syntax in 'grid-template' shorthand syntax--
4275-
since this is somewhat incompatible with the ASCII-art design of the syntax, and was never intended to be allowed.
4276-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-3">Issue 3</a>)
4277-
<li>Clamped <a>automatic minimum size</a> of grid items inside tracks with <a>fixed sizing functions</a>.
4278-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-15">Issue 15</a>)
4279-
<li>Fixed handling of ''fit-content()'' in the track sizing algorithm.
4280-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-13">Issue 13</a>)
4281-
<li>Allowed UAs to (optionally) back-compute percentage track sizes.
4282-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-26">Issue 26</a>)
4283-
<li>Correctly and completely defined ''auto''-sizing of grid items.
4284-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-21">Issue 21</a>)
4285-
<li>Made the handling of <a>collapsed tracks</a> more explicit.
4286-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-8">Issue 8</a>)
4287-
<li>Fixed grammar error in definition of <<auto-track-list>>.
4288-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-1">Issue 1</a>)
4289-
<li>Fixed some tangled up text about how subgrids receive line names from their parent grid.
4290-
<li>Clarified that percentage gutters are calculated exactly like empty percentage tracks.
4291-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-20">Issue 20</a>)
4292-
<li>Made missing baselines synthesize from the border box.
4293-
(<a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519#issue-22">Issue 22</a>)
4294-
<li>Miscellaneous minor clarifications.
4311+
<li>Applied flex factor clamping to 1 also to indefinite case.
4312+
(See <a href="https://lists.w3.org/Archives/Public/www-style/2015Sep/0032.html">discussion</a>.)
4313+
<li>Fixed automatic sizing of grid items with an intrinsic ratio
4314+
so that they maintain their intrinsic ratio
4315+
whenever the alignment properties are ''align-self/normal'' (the default case).
42954316
</ul>
42964317

4297-
A <a href="https://drafts.csswg.org/css-grid-1/issues-wd-20160519">Disposition of Comments</a> is available.
4298-
See also <a href="https://www.w3.org/TR/2016/WD-css-grid-1-20160519/#changes">previous changes</a>.
4299-
43004318
Privacy and Security Considerations {#priv-sec}
43014319
===============================================
43024320

0 commit comments

Comments
 (0)