Skip to content

Commit c50164e

Browse files
committed
[css-grid] First pass at repeat(auto-fill|auto-fit) syntax.
1 parent 7bae04a commit c50164e

2 files changed

Lines changed: 1083 additions & 3357 deletions

File tree

css-grid/Overview.bs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ Track Sizing: the 'grid-template-rows' and 'grid-template-columns' properties</h
934934

935935
<pre class='propdef'>
936936
Name: grid-template-columns, grid-template-rows
937-
Value: none | <<track-list>> | subgrid <<line-name-list>>?
937+
Value: none | <<track-list>> | <<auto-track-list>> | subgrid <<line-name-list>>?
938938
Initial: none
939939
Applies to: <a>grid containers</a>
940940
Inherited: no
@@ -969,11 +969,16 @@ Track Sizing: the 'grid-template-rows' and 'grid-template-columns' properties</h
969969
The syntax of a <a>track list</a> is:
970970

971971
<pre>
972-
<dfn>&lt;track-list></dfn> = [ <<line-names>>? [ <<track-size>> | <<repeat()>> ] ]+ <<line-names>>?
973-
<dfn>&lt;track-size></dfn> = minmax( <<track-breadth>> , <<track-breadth>> ) | <<track-breadth>>
974-
<dfn>&lt;track-breadth></dfn> = <<length>> | <<percentage>> | <<flex>> | min-content | max-content | auto
975-
<dfn>&lt;line-names></dfn> = '[' <<custom-ident>>* ']'
976-
<dfn>&lt;line-name-list></dfn> = [ <<line-names>> | repeat([ <<positive-integer>> | auto ], <<line-names>>+) ]+
972+
<dfn>&lt;track-list></dfn> = [ <<line-names>>? [ <<track-size>> | <<track-repeat>> ] ]+ <<line-names>>?
973+
<dfn>&lt;auto-track-list></dfn> = [ <<line-names>>? [ <<fixed-size>> | <<fixed-repeat>> ] ]+ <<auto-repeat>>
974+
[ <<line-names>>? [ <<fixed-size>> | <<fixed-repeat>> ] ]+ <<line-names>>?
975+
<dfn>&lt;line-name-list></dfn> = [ <<line-names>> | <<name-repeat>> ]+
976+
977+
<dfn>&lt;track-size></dfn> = <<track-breadth>> | minmax( <<track-breadth>> , <<track-breadth>> )
978+
<dfn>&lt;fixed-size></dfn> = <<fixed-breadth>> | minmax( <<fixed-breadth>> , <<track-breadth>> )
979+
<dfn>&lt;track-breadth></dfn> = <<length>> | <<percentage>> | <<flex>> | min-content | max-content | auto
980+
<dfn>&lt;fixed-breadth></dfn> = <<length>> | <<percentage>>
981+
<dfn>&lt;line-names></dfn> = '[' <<custom-ident>>* ']'
977982
</pre>
978983

979984
Where:
@@ -1027,6 +1032,9 @@ Track Sizing: the 'grid-template-rows' and 'grid-template-columns' properties</h
10271032
As a maximum, identical to ''max-content''.
10281033
As a minimum, represents the largest minimum size (as specified by 'min-width'/'min-height')
10291034
of the <a>grid items</a> occupying the <a>grid track</a>.
1035+
1036+
Note: ''grid-template-rows/auto'' track sizes (and only ''grid-template-rows/auto'' track sizes)
1037+
can be streched by the 'align-content' and 'justify-content' properties.
10301038
</dl>
10311039

10321040
<div class='example'>
@@ -1131,20 +1139,31 @@ Named Grid Lines: the <css>[<<custom-ident>>*]</css> syntax</h4>
11311139
<h4 id='repeat-notation'>
11321140
Repeating Rows and Columns: the ''repeat()'' notation</h4>
11331141

1134-
The ''repeat()'' notation represents a repeated fragment of the <a>track list</a>,
1142+
The <dfn>repeat()</dfn> notation represents a repeated fragment of the <a>track list</a>,
11351143
allowing a large number of columns or rows that exhibit a recurring pattern
11361144
to be written in a more compact form.
1137-
The syntax of the ''repeat()'' notation is:
1145+
The syntax of the ''repeat()'' notation
1146+
has several forms:
11381147

11391148
<pre class='prod'>
1140-
<dfn>repeat()</dfn> = repeat( <<positive-integer>>, [ <<line-names>>? <<track-size>> ]+ <<line-names>>? ) |
1149+
<dfn><<track-repeat>></dfn> = repeat( <<positive-integer>>, [ <<line-names>>? <<track-size>> ]+ <<line-names>>? )
1150+
<dfn><<auto-repeat>></dfn> = repeat( [ auto-fill | auto-fit ], [ <<line-names>>? <<fixed-size>> ]+ <<line-names>>? )
1151+
<dfn><<fixed-repeat>></dfn> = repeat( <<positive-integer>>, [ <<line-names>>? <<fixed-size>> ]+ <<line-names>>? )
1152+
<dfn><<name-repeat>></dfn> = repeat( [ <<positive-integer>> | auto-fill ], <<line-names>>+)
11411153
</pre>
11421154

11431155
The first argument specifies the number of repetitions.
11441156
The second argument is a <a>track list</a>,
11451157
which is repeated that number of times.
1146-
The ''repeat()'' notation cannot be nested;
1147-
doing so makes the declaration invalid.
1158+
1159+
* The <<track-repeat>> variant can represent the repeatition of any <<track-size>>,
1160+
but is limited to fixed repetitions.
1161+
* The <<auto-repeat>> variant can repeat automatically to fill a space,
1162+
but requires <a>definite</a> minimum track sizes so that the number of repetitions can be calculated.
1163+
It can only appear once in the <a>track list</a>,
1164+
but the same <a>track list</a> can also contain <<fixed-repeat>>s.
1165+
* The <<name-repeat>> variant can be used with the ''grid-template-rows/subgrid'' keyword:
1166+
it only repeats names.
11481167

11491168
<div class='example'>
11501169
This example shows two equivalent ways of writing the same grid definition.
@@ -1179,30 +1198,21 @@ Repeating Rows and Columns: the ''repeat()'' notation</h4>
11791198
<h5 id="repeat-auto">
11801199
Repeat-to-fill</h5>
11811200

1182-
Issue: We're trying to solve <a href="https://lists.w3.org/Archives/Public/www-style/2014Oct/0108.html">this problem</a>,
1183-
which should be easy, but isn't at the moment.
1184-
1185-
<pre class="prod">
1186-
<dfn><<auto-repeat>></dfn> = repeat( auto, [ <<line-names>>? [ <<length>> | <<percentage>> ] ]+ <<line-names>>? )
1187-
</pre>
1188-
1189-
If the number of repetitions is <dfn value for=repeat()>auto</dfn>
1190-
and the <a>grid container</a> has a <a>definite</a> size or max size in the relevant axis,
1191-
then the number of repetitions is the largest possible integer
1201+
When <dfn for="repeat()">''auto-fill''</dfn> is given as the repetition number,
1202+
if the <a>grid container</a> has a <a>definite</a> size or max size in the relevant axis,
1203+
then the number of repetitions is the largest possible positive integer
11921204
that does not cause the <a>grid</a> to overflow its <a>grid container</a>
1193-
(treating all tracks as their <a>max track sizing function</a> if that is <a>definite</a> or as zero otherwise).
1194-
Otherwise, the <a>track list</a> repeats only once.
1195-
A <<track-list>> with more than one ''repeat()/auto'' ''repeat()'' function,
1196-
or with any content-sized tracks in addition to the ''repeat()/auto'' ''repeat()'' function,
1197-
is invalid.
1198-
1199-
Issue: François suggests a way to generate "just enough" repeated columns for the number of items in the grid.
1200-
<a href="https://lists.w3.org/Archives/Public/www-style/2015May/0113.html">(see discussion)</a>
1201-
One proposal is to have two keywords instead of just one ''repeat()/auto'' keyword:
1202-
<css>auto-fill</css> to fill the grid with repetitions,
1203-
and <css>auto-fit</css> to fill the grid and then drop empty repetitions.
1205+
(treating each track as its <a>max track sizing function</a> if that is <a>definite</a>
1206+
or as its minimum track sizing function otherwise).
1207+
Otherwise, the specified <a>track list</a> repeats only once.
12041208

1209+
The <dfn for="repeat()">''auto-fit''</dfn> keyword behaves the same as ''auto-fill'',
1210+
except that after <a href="#auto-placement-algo">grid item placement</a>
1211+
any empty repetitions are dropped.
12051212

1213+
Issue: Now that we have gutters, most use cases for auto-repetition will need only one track size.
1214+
It would also be much simpler for implementations if only one track size were allowed.
1215+
Should we simplify the argument to the <<auto-repeat>> functions to only allow one <<fixed-size>>?
12061216

12071217
<!--
12081218
████████ ████████ ██ ██ ██ ██ ████ ████████
@@ -3648,7 +3658,9 @@ Changes</h2>
36483658

36493659
* Renamed <css>row-gap</css>/<css>column-gap</css> to 'grid-row-gap'/'grid-column-gap'
36503660
to avoid having multicol and grid share 'column-gap'.
3651-
This also preserves <css>'grid-'</css> as a prefix across these properties and their shorthand.
3661+
This also preserves <css>grid-</css> as a prefix across these properties and their shorthand.
3662+
* Split ''auto'' into ''auto-fill' and ''auto-fit'' keywords for ''repeat()'' notation,
3663+
adjusted grammar to prevent
36523664
36533665
The following significant changes were made since the
36543666
<a href=http://www.w3.org/TR/2015/WD-css-grid-1-20150317/>17 March 2015 Working Draft</a>.

0 commit comments

Comments
 (0)