8000 [css3-layout] Added 'position: grid' (and 'display: grid' as its · xfq/csswg-drafts@f256cdf · GitHub
Skip to content

Commit f256cdf

Browse files
committed
[css3-layout] Added 'position: grid' (and 'display: grid' as its
abbreviation) for switching between 'flow' and 'grid-area'. When 'position' is 'grid', the computed value of 'display' is always 'block', rather than computed as for 'absolute'.
1 parent 318e590 commit f256cdf

1 file changed

Lines changed: 81 additions & 89 deletions

File tree

css-template/Overview.src.html

Lines changed: 81 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,25 +1743,7 @@ <h3 id=slot-sizes>Calculating the size of the grid</h3>
17431743

17441744
<!--=================================================================-->
17451745

1746-
<h2 id=positioning>Putting content into a grid element</h2>
1747-
1748-
<p><em>This section until the next subsection is not normative.</em>
1749-
1750-
<p>Grids can be used in two different ways to position content. The
1751-
first way is to flow content into slots (either into explicit slots
1752-
identified by name, or the default slot “*”). Each slot is an
1753-
individual flow root (“establishes a block formatting context” in the
1754-
terminology of CSS level 2), very much like a table cell.
1755-
1756-
<p>The second way is to absolutely position elements using
1757-
four <em>grid lines</em> to specify the positions of the four margin
1758-
edges of the element. Like other positioned elements
1759-
[[!CSS21]], these elements can overlap each other and the 'z-index'
1760-
property applies to them.
1761-
1762-
<!--=================================================================-->
1763-
1764-
<h3 id=flow>Flowing content into slots: 'flow'</h3>
1746+
<h2 id=flow>Flowing content into slots: 'flow'</h2>
17651747

17661748
<p>The 'flow' property adds an element to a slot.
17671749

@@ -1772,8 +1754,7 @@ <h3 id=flow>Flowing content into slots: 'flow'</h3>
17721754
<var>&lt;identifier&gt;</var> | <var>&lt;string&gt;</var> | '*' | same
17731755
<tr><th>Initial: <td>auto
17741756
<tr><th>Applies to: <td>elements that have a <span>grid
1775-
ancestor</span> and whose 'position' is ''static'' or ''relative'' and
1776-
whose 'grid-area' is ''none''
1757+
ancestor</span> and whose 'position' is ''static'' or ''relative''
17771758
<tr><th>Inherited: <td>no
17781759
<tr><th>Animatable: <td>no
17791760
<tr><th>Percentages: <td>N/A
@@ -2156,19 +2137,76 @@ <h3 id=flow>Flowing content into slots: 'flow'</h3>
21562137

21572138
<!--=================================================================-->
21582139

2140+
<h2 id=absolute>Absolute positioning on top of a grid</h2>
2141+
2142+
<p><em>This section, until the next subsection, is not normative.</em>
2143+
2144+
<p>A new ''grid'' value of the 'position' property allows alements to
2145+
be taken out of their parent's flow (as with 'position: absolute' or
2146+
'position: fixed') while still using the grid lines for alignments and
2147+
also still contributing to the size of slots.
2148+
2149+
<p>For the special case that all children of a <em>grid element</em>
2150+
are to be positioned in this way (which is expected to be common when
2151+
HTML and CSS are used to create <abbr title="Graphical User
2152+
Interfaces">GUIs</abbr>), a new ''grid'' value for 'display' provides
2153+
an abbreviation.
2154+
2155+
<p>
2156+
2157+
<!--=================================================================-->
2158+
2159+
<h3>Taking elements out of the flow with 'position: grid' or 'display: grid'</h3>
2160+
2161+
<table class=propdef-extra>
2162+
<tbody>
2163+
<tr><th>Name: <td><dfn>position</dfn>
2164+
<tr><th><a href="#values" >Value</a>: <td>grid
2165+
</table>
2166+
2167+
<table class=propdef-extra>
2168+
<tbody>
2169+
<tr><th>Name: <td><dfn>display</dfn>
2170+
<tr><th><a href="#values" >Value</a>: <td>grid
2171+
</table>
2172+
2173+
<p>Setting 'position: grid' on an element that has a <em>grid
2174+
ancestor</em> causes the element to be taken out of the flow of its
2175+
parent and positioned with 'grid-area'. It also sets the computed
2176+
value of 'display' to 'block'. If the element does not have a grid
2177+
ancestor, 'position: grid' is treated as if it were 'position: static'
2178+
and 'display' is not affected.
2179+
2180+
<p>Setting 'display: grid' on an element has the same effect as
2181+
setting 'display: block'. In addition, when the element is a <em>grid
2182+
element,</em> it sets the computed value of 'position' on its children
2183+
to ''grid''.
2184+
2185+
<div class=example>
2186+
<p>For example, the following two style sheets are equivalent:
2187+
<pre>
2188+
DIV {grid: "a b c"; display: block}
2189+
DIV > * {position: grid}
2190+
</pre>
2191+
2192+
<p>and
2193+
<pre>
2194+
DIV {grid: "a b c"; display: grid}
2195+
</pre>
2196+
</div>
2197+
21592198
<h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
21602199

21612200
<table class=propdef>
21622201
<tbody>
21632202
<tr><th>Name: <td><dfn>grid-area</dfn>
2164-
<tr><th><a href="#values" >Value</a>: <td>none | auto |
2203+
<tr><th><a href="#values" >Value</a>: <td>auto |
21652204
<var>&lt;identifier&gt;</var> | <var>&lt;string&gt;</var> | [
21662205
<var>&lt;integer&gt;</var> | same | next ]{2} [
21672206
<var>&lt;integer&gt;</var>{2} ]?
21682207
<tr><th>Initial: <td>none
21692208
<tr><th>Applies to: <td>elements that have a <span>grid
2170-
ancestor</span> and whose 'position' is equal to 'static' or
2171-
'relative'
2209+
ancestor</span> and whose 'position' is equal to 'grid'
21722210
<tr><th>Inherited: <td>no
21732211
<tr><th>Animatable: <td>no
21742212
<tr><th>Percentages: <td>N/A
@@ -2184,8 +2222,7 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
21842222
<tr><th><a href="#values" >Value</a>: <td>none | rows | columns
21852223
<tr><th>Initial: <td>none
21862224
<tr><th>Applies to: <td>elements that have a <span>grid
2187-
ancestor</span> and whose 'position' is equal to 'static' or
2188-
'relative'
2225+
ancestor</span> and whose 'position' is equal to 'grid'
21892226
<tr><th>Inherited: <td>yes
21902227
<tr><th>Animatable: <td>no
21912228
<tr><th>Percentages: <td>N/A
@@ -2196,18 +2233,6 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
21962233
</table>
21972234

21982235
<div class=issue>
2199-
<p>In [[CSS3-GRID-LAYOUT]] (version of April 2013) there is no
2200-
'grid-area: none' but 'grid-area' only applies when 'position' is set
2201-
to 'grid' (a new keyword).
2202-
2203-
<p>There was also discussion (at the June 2013 ftf) to set a property
2204-
on the grid element itself to enable positioning of descendants. When
2205-
set (e.g., 'grid-mode: absolute'), all children are placed by means of
2206-
their 'grid-area' property, when not set ('grid-mode: normal'),
2207-
'grid-area' is ignored. That would preclude mixing flowing and
2208-
positioned descendants (except, perhaps, if it is an inherited
2209-
property and descendants can override it).
2210-
22112236
<p>At the Aug 2012 ftf, Florian suggested a property 'collision: auto
22122237
| collide | avoid' to switch between overlapping and not overlapping.
22132238
(It would avoid collisions for absolutely positioned elements as
@@ -2224,19 +2249,13 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
22242249
'grid-area' may be easier to learn.
22252250
</div>
22262251

2227-
<p>The 'grid-area' property can take an element out of the flow and
2228-
position it relative to a grid. Unless the value of 'grid-area' is
2229-
''none'', the 'z-index' property applies and determines the
2230-
stacking level. If the element has no <span>grid ancestor,</span> the
2231-
element is positioned as if the value were ''none''. The values have
2232-
the following meanings:
2252+
<p>The 'grid-area' property positions an element relative to a grid.
2253+
If the property applies, the 'z-index' property determines the
2254+
stacking level.
22332255

2234-
<dl>
2235-
<dt>none
2236-
<dd>
2237-
<p>The element is positioned according to its 'flow'
2238-
property.
2256+
<p>The values have the following meanings:
22392257

2258+
<dl>
22402259
<dt><var>&lt;identifier&gt;</var>
22412260
<dt><var>&lt;string&gt;</var>
22422261
<dd>
@@ -2249,11 +2268,9 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
22492268
''default'', ''same'', or ''next''. This is to avoid ambiguity with
22502269
the keywords of the same name.
22512270

2252-
<p>If the name refers to a non-existent slot, the value is interpreted
2253-
as if it were ''none''.
2254-
2255-
<p class=issue>See the <a href="#non-existent-slot">issue about
2256-
non-existent slot names</a> under 'flow' for other possibilities.
2271+
<p>If the name refers to a non-existent slot, <span
2272+
class=issue>[define (see the <a href="#non-existent-slot">issue about
2273+
non-existent slot names</a> under 'flow' for possibilities).</span>
22572274
<dt>
22582275

22592276
<dt>auto
@@ -2361,41 +2378,16 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
23612378
'grid-auto'/''auto'' do the same thing in different ways. We need only
23622379
one. Which is easier?
23632380

2364-
<p>If an elements has a 'grid-area' other than ''none'', then the
2365-
'float' property does not apply and the values of 'display' are
2366-
determined according to this table:
2367-
2368-
<table class=equiv-table>
2369-
<thead>
2370-
<tr>
2371-
<th>Specified value <th>Computed value
2372-
<tbody>
2373-
<tr>
2374-
<td>inline-table <td>table
2375-
<tr>
2376-
<td>inline, table-row-group, table-column, table-column-group,
2377-
table-header-group, table-footer-group, table-row, table-cell,
2378-
table-caption, inline-block, run-in, compact, ruby, ruby-base,
2379-
ruby-text, ruby-base-group, ruby-text-group <td>block
2380-
<tr>
2381-
<td>inline-flex <td>flex
2382-
<tr>
2383-
<td>others <td>same as specified
2384-
</table>
2385-
2386-
<p class=note>Note that “others” includes ''list-item'', ''table'',
2387-
''container' ''flex'' and of course ''none''.
2388-
2389-
<p class=issue>Check that the list above covers everything in
2390-
[[CSS3BOX]].
2381+
<p>If 'grid-area' applies, then the 'float' property does not apply
2382+
and the computed value of 'display' is ''block''.
23912383

23922384
<div class=example>
23932385
<p>For example, these rules
23942386

23952387
<pre>
23962388
DIV {grid: "a b"
23972389
"c d"}
2398-
P {position: absolute; grid-area: b}
2390+
P {position: grid; grid-area: b}
23992391
</pre>
24002392

24012393
<p>means that any P exactly overlaps slot b.
@@ -2405,8 +2397,8 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
24052397
<p>For example, this document fragment
24062398
<pre>
24072399
&lt;DIV STYLE="grid: 'a b b'"&gt;
2408-
&lt;P STYLE="grid-area: a"&gt;...
2409-
&lt;P STYLE="grid-area: next same"&gt;...
2400+
&lt;P STYLE="position: grid; grid-area: a"&gt;...
2401+
&lt;P STYLE="position: grid; grid-area: next same"&gt;...
24102402
&lt;/DIV&gt;
24112403
</pre>
24122404
<p>puts the second P in the left half of slot b, because the first P
@@ -2448,15 +2440,15 @@ <h3>Stacking elements on top of a grid: 'grid-area' and 'grid-auto'</h3>
24482440
<pre>
24492441
TABLE {grid: "*"}
24502442
TD:first-child {grid-area: next 1}
2451-
TD {grid-area: same next}
2443+
TD {position: grid; grid-area: same next}
24522444
</pre>
24532445

24542446
<div class=issue>
24552447
<p>Or with 'grid-auto':
24562448

24572449
<pre>
24582450
TABLE {grid: "*"}
2459-
TD {grid-area: auto; grid-auto: columns}
2451+
TD {position: grid; grid-area: auto; grid-auto: columns}
24602452
TD:first-child {grid-auto: rows}
24612453
</pre>
24622454
</div>
@@ -3969,7 +3961,7 @@ <h4 id=auto-add>Automatically add rows and columns</h4>
39693961
<pre>
39703962
TABLE {grid-columns: auto; grid-rows: auto}
39713963
TD:first-child {grid-area: next 1}
3972-
TD {grid-area: same next}
3964+
TD {position: grid; grid-area: same next}
39733965
</pre>
39743966

39753967
<p>This uses keywords instead of numbers, as described in <a
@@ -4286,7 +4278,7 @@ <h4>Use the pseudo-class to create additional slots</h4>
42864278
to an element in the document you could create a pseudo-element that
42874279
is like an “absolutely positioned slot:”
42884280

4289-
<pre>DIV::slot(z) {position: absolute; grid-area: 2 2}</pre>
4281+
<pre>DIV::slot(z) {position: grid; grid-area: 2 2}</pre>
42904282

42914283
<p>Like other '::slot()' pseudo-elements, it applies to <span>grid
42924284
elements</span> only (the DIV in this example must be a grid element),
@@ -4329,7 +4321,7 @@ <h4>Names for edges</h4>
43294321
/* Create a 7x2 grid template */
43304322
DIV {grid-columns: * a-line * * b-line * *; grid-rows: * *}
43314323
/* Put H2 at cell x=4, y=2 */
4332-
DIV H2 {position: absolute; grid-area: b-line 2}
4324+
DIV H2 {position: grid; grid-area: b-line 2}
43334325
</pre>
43344326

43354327
<p>(This could also use strings instead of identifiers, for even more

0 commit comments

Comments
 (0)