8000 csswg-drafts/css3-layout/new2.src.html at e3cc30ee71f6d684fe365e5b9b6a4fd07ee4e498 · xfq/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
4147 lines (3266 loc) · 135 KB

File metadata and controls

4147 lines (3266 loc) · 135 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang=en>
<head
profile="http://microformats.org/profile/hcard http://microformats.org/wiki/rel-license">
<title>CSS Grid Template Layout Module</title>
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<link href="../default.css" rel=stylesheet type="text/css">
<style type="text/css">
.prod { font-family: inherit; font-size: inherit }
pre.prod { white-space: pre-wrap; margin: 1em 0 1em 2em }
code { font-size: inherit; }
.level4 {color: gray; clear: both}
.level4 h2, .level4 h3, .level4 h4 {color: inherit}
p.level4:before, div.level4:before, li.level4:before {
content: "LEVEL\A 4"; background: #BBB; color: white; white-space: pre;
text-align: center; float: left; margin: 0 0.3em 0.1em 0; min-width: 0;
border-radius: 100%; line-height: 1; font-size: small;
padding: 1.1em 0.4em 0.6em 0.4em}
.example .visible {border: thin dotted silver}
/* delete this block when you've cleared out all the .replaceme elements */
.replaceme {
border: solid red;
padding: 0 0.5em;
margin: 0 0.1em;
background: yellow;
color: green;
}
.replaceme:before {
content: "FIXME(";
color: black;
}
.replaceme:after {
content: ")";
color: black;
}
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-MO.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--logo-->
<h1>CSS Grid Template Layout Module</h1>
<!--=================================================================-->
<h2 class="no-num no-toc">[LONGSTATUS] [DATE: 3 August 2004]</h2>
<dl>
<dt>This version:
<dd><a href="[VERSION]"
>http://www.w3.org/TR/[YEAR]/ED-[SHORTNAME]-[CDATE]/</a>
<dt>Latest version:
<dd> <a href="[LATEST]">http://www.w3.org/TR/css3-layout/</a>
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2011/WD-css3-layout-20111129/"
>http://www.w3.org/TR/2011/WD-css3-layout-20111129/</a>
<dt>Editors:
<dd class=vcard><span class=fn>Bert Bos</span> (<span
class=org>W3C</span>) <a class=email href="mailto:bert@w3.org"
rel=author>bert@w3.org</a>
<dd class=vcard><span class=fn>César Acebal</span> (<span
class=org>University of Oviedo</span>)
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<!--=================================================================-->
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<div class=sidefigure>
<p><img alt="Image: four elements move to four slots in a template"
longdesc=diagram.desc src=diagram.png>
<p class=caption>Above: a typical Web page. Below: the underlying grid
template.
</div>
<p>CSS is a simple, declarative language for creating style sheets that
specify the rendering of HTML and other structured documents. This
module defines a typographic grid for CSS. It has features to set up a
grid template, to flow content into it, and to absolutely position
elements on a grid.
<p>The 'grid' property sets up a matrix of rows and columns and
designates empty areas and areas for content (called “slots”). The
'flow' property specifies into which slot an element flows. A grid
templates is like a table in that the various slots are aligned in rows
and columns and can automatically adapt to each others size, and it is
like absolute positioning in that elements can be put in arbitrary
slots so that the visual order becomes independent of the document
order.
<p>The '::slot()' pseudo-element allows to style the slots
(backgrounds, borders, etc.)
<p>The 'grid-position' property can be used instead of the 'top',
'left', 'right' and 'bottom' properties from level 2 to position
absolutely positioned elements relative to a grid template, so that
they align with the content in the grid.
<p class=level4>Grid templates can also be associated with pages in
paged media, to create page templates.
<p class=level4>Slots can also form “chains” to create
non-rectangular regions. A chain of slots is like a series of pages or
columns: content is distributed over the slots by breaking it at
possible break points (see the 'break-*' properties from
[[CSS3-BREAK]]).
<p class=level4>The '::fragment()' pseudo-element allows to select
(parts of) elements based on whether they fall in a certain slot or
not, and thus style content differently in different slots
(region-based styling).
<!--=================================================================-->
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--status-->
<p>This draft combines ideas from earlier drafts on Template Layout,
Grid Positioning [[CSS3GRID]] and Grid Layout [[CSS3-GRID-LAYOUT]].
<p>The section on <a href="#cr-exit-criteria">“CR exit criteria”</a>
lists some conditions for this specification to become a W3C
Recommendation.
<p>Issues on this draft are mentioned in the text itself
(<span class=issue>like this</span>) and/or in the on-line Tracker
under <a href="http://www.w3.org/Style/CSS/Tracker/products/15"
>“Details on Product CSS3 Template Layout.”</a>
<!--=================================================================-->
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--toc-->
<!--=================================================================-->
<h2>Introduction</h2>
<p><em>(This section is not normative.)</em>
<h3>Summary and examples</h3>
<div class=sidefigure>
<p><img alt="Image: four elements move to four slots in a template"
longdesc=diagram.desc src=diagram.png>
<p class=caption>Above: a typical Web page. Below: the underlying grid
template. It has four slots, a, b, c and d and the grid template is
defined by 'grid: "aaaaaaa" "bccccdd"'.
</div>
<p class=mtb>The styling of a Web page, a form or a graphical user
interface can roughly be divided in two parts: (1) defining the overall
“grid” of the page or window and (2) specifying the fonts, indents,
colors, etc., of the text and other objects. The two are not completely
separate, of course, because indenting or coloring a text influences
the perceived grid as well. Nevertheless, when one separates the parts
of a style that should change when the window gets bigger from the
parts that stay the same, one often finds that the grid changes (room
for a sidebar, extra navigation bar, big margins, larger images…),
while fonts, colors, indents, numbering styles, and many other things
don't have to change, until the size of the window becomes extreme.
<p>The properties in this specification work by associating a layout
grid with an element. Rather than letting an element lay out its
descendants in a single flow, the policy defined in this module gives
an element a <span>grid template,</span> which is a set
of <span>slots</span> aligned to an invisible grid, where each slot is
a separate flow. The descendants are given a 'flow' property to
designate the slot into which they flow.
<p>Because layouts on the Web have to adapt to different window and
paper sizes, the rows and columns of the grid can be made fixed or
flexible in size.
<p>The typical use cases for these properties include:
<ul>
<li><p>Complex Web pages, with multiple navigation bars in fixed
positions, areas for advertisements, etc.
<li><p>Complex forms, where the alignment of labels and form fields may
be easier with the properties of this module than with the properties
for tables and margins.
<li><p>GUIs, where buttons, toolbars, labels, icons, etc., are aligned in
complex ways and have to stay aligned (and not wrap, for example) when
the window is resized.
<li><p class=level4>Paged displays (e.g., printed media) where each page
is divided in fixed areas for different kinds of content.
<li><p class=level4>Complex pages with multiple regions, where the style
of the text does not only depend on the type of element it comes from,
but also on the region it is displayed in.
</ul>
<p>Once a grid template has been defined, it can also be used as an
alternative coordinate system for absolutely positioned elements. Such
elements do not flow into slots, but, by using 'grid-position'
(instead of 'top', 'left' etc.) can be aligned to grid lines and thus
to the content in the grid.
<p>But for many applications, template-based positioning makes
absolute positioning unnecessary. Like absolute positioning, grid
templates are especially useful for aligning elements that don't have
simple relationships in the source (parent-child, ancestor-descendant,
immediate sibling). But in contrast to absolute positioning, the
elements are not positioned with the help of horizontal and vertical
coordinates, but by flowing them into a template that is very much
like a table: The size and alignment of elements are governed
implicitly by the rows and columns of the template, and can
automatically adapt to the overall size of the element and to the
content in each row and column.
<div class=example>
<p>In this example, the four children of an element are assigned to
four slots (called a, b, c and d) in a 2×2 template. (All mark-up
examples in this specification are HTML fragments, unless otherwise
stated.)
<div class=sidefigure>
<p><img alt="Image: sample rendering" longdesc=aapje.desc
src=aapje.png>
<p class=caption>Each element occupies one slot. In this template, all
slots have the same size.
</div>
<pre>
&lt;style type="text/css"&gt;
dl { grid: "ab"
"cd" }
#sym1 { flow: a }
#lab1 { flow: b }
#sym2 { flow: c }
#lab2 { flow: d }
&lt;/style&gt;
&lt;dl&gt;
&lt;dt id=sym1&gt;A
&lt;dd id=lab1&gt;A is een aapje
&lt;dt id=sym2&gt;B
&lt;dd id=lab2&gt;B is de bakker
&lt;/dl&gt;
</pre>
</div>
<div class=example>
<p>Templates can also help with device-independence. This example uses
Media Queries [[MEDIAQ]] to change the overall layout of a page from
3-column layout for a wide screen to a 1-column layout for a narrow
screen. It assumes the page has been marked-up with logical sections
with IDs.
<pre>
@media all
{
body { grid: "aaa"
"bcd" }
#head { flow: a }
#nav { flow: b }
#adv { flow: c }
#body { flow: d }
}
@media all and (max-width: 500px)
{
body { grid: "a"
"b"
"c" }
#head { flow: a }
#nav { flow: b }
#adv { display: none }
#body { flow: c }
}
</pre>
</div>
<div class=example>
<p>The slots in a grid do not overlap, unless with negative margins.
Here is how
the <a
href="http://www.csszengarden.com/?cssfile=/026/026.css&amp;page=0" >
“zunflower” design</a> of the CSS Zen Garden could be done:
<pre>
#container {grid: "abc"}
#container::slot(a) {box-shadow: 0.5em 0.5em 0.5em; z-index: 1}
#container::slot(b) {box-shadow: 0.5em 0.5em 0.5em; margin-left: -2em}
#intro {flow: a}
#supportingText {flow: b}
#linkList {flow: c}
</pre>
</div>
<div class=example>
<p>Template-based positioning borrows some concepts from table layout,
in particular the idea of aligning elements in rows and columns, so
that they constrain one another's size. But there are also
differences. This example shows some of them. Assume this document
fragment:
<pre>
&lt;div class=group>
&lt;div>aa aa aa aa aa aa&lt;/div>
&lt;div>bbb&lt;/div>
&lt;div class=menu>ccccc&lt;/div>
&lt;/div>
</pre>
<p>We can lay it out as three columns, as the following illustrations
show. The style sheet would contain the following.
<pre>
.group {display: table}
.group > div {display: table-cell}
</pre>
<div class=figure>
<p><img alt="[Three unequal cells]" longdesc=table1.desc
src=table1.png>
<p class=caption>Example of rendering with a table.
</div>
<p>We can also use a template, in which case the style sheet would
contain this:
<pre>
.group {grid: "abc"}
.group > div {flow: a}
.group > div + div {flow: b}
.group > div + div + div {flow: c}
</pre>
<p>By default, the table is as wide as needed to fit its contents. To
make sure it is as wide as its containing block, we need to add
<pre>.g 6D50 roup {display: table; width: 100%}</pre>
<p>That is not needed for the grid template, but, on the other hand,
if we want the template to fit its contents, we would need to say so:
<pre>.group {grid: "abc"; width: auto}</pre>
<p>(See [[!CSS3BOX]] for the definition of the 'width' property.) The
columns of the template are by default all the same size. The columns
of the table satisfy certain constraints, but the exact size is not
defined. We can make them all the same by adding a rule (see
[[!CSS3TBL]]):
<pre>.group {display: table; width: 100%; table-layout: fixed}</pre>
<div class=figure>
<p><img alt="[Three equal cells]" longdesc=table2.desc src=table2.png>
<p class=caption>Example of rendering with equal columns.
</div>
<p>In both styles, we can set a column to a certain size:
<pre>div.menu {width: 3em}</pre>
<p>resp.,
<pre>.group {grid: "abc" * * 3em}</pre>
<div class=figure>
<p><img alt="[Two equal cells, third is 3em wide]"
longdesc=table3.desc src=table3.png>
<p class=caption>Example of rendering with a fixed third column and
the other two columns of equal width.
</div>
<p>If there is an unknown number of columns (children of the div.group
element), the style sheet for the table model will automatically take
them into account. The style sheet for the template model, however,
creates a template of exactly three columns and can't handle tables
with an unknown number of columns. The extra elements will be added
into the default slot (in this case the ''a'' slot).
<p>(However, extra columns or rows <em>will</em> be created if
necessary to absolutely position elements. See the 'grid-position'
property.)
<p>In both models, elements can have borders, but only in the table
model can borders be collapsed, which makes setting borders easier in
the table model:
<pre>
.group {display: table; border-collapse: collapse}
.group > div {border: solid}
</pre>
<p>resp.,
<pre>
.group > div {border: solid; border-left: none}
.group > div:first-child {border-left: solid}
</pre>
<p>In the template model, the order of the elements is explicit, and
thus it is possible to reverse the order of the columns:
<pre>
.group > div {flow: c}
.group > div + div {flow: b}
.group > div + div + div {flow: a}
</pre>
<div class=figure>
<p><img alt="[Different contents for the cells]" longdesc=table4.desc
src=table4.png>
<p class=caption>Example of rendering with the contents of the three
columns reversed: the third element is shown in the first slot and the
first element in the third slot.
</div>
<p>In the table model, the order of the rows and columns is given by
the document source and thus can't be changed.
</div>
<div class=example>
<p>This example shows a way to move notes to the end of a section.
“Notes” in this example refers to elements in HTML with a class of
“note”. A fragment of HTML such as
<pre>
&lt;div class=section>
&lt;p>The balubious coster of the fifth secter&lt;span
class=note> The sixth secter coster is a difter
manon.&lt;/span> of The Rollow Carpug mentizes a costernica.
&lt;p>&hellip;
&lt;/div>
</pre>
<p>with this style sheet
<pre>
div.section {
grid: "*"
"F"}
.note {
flow: F;
content: counter(note) ".\A0" contents;
counter-increment: note;
font-size: smaller}
.note::before {
content: counter(note);
vertical-align: super;
font-size: larger}
</pre>
<p>results in a rendering similar to this:
<div class=figure>
<p><img alt="Same text, with the SPAN replaced by “(1)” and its
content moved to the end." longdesc=footnotes.desc src=footnotes.png>
<p class=caption>Rendering of a text with footnotes.
</div>
<p>The “Generated content for paged media” module [[CSS3GCPM]] is
expected to define specific features for footnotes that are both
easier and more powerful than this example.
</div>
<div class="example level4">
<p>This example shows the use of chained regions: text from region 1
continues in region 2, 3 and 4. And it shows how to use
pseudo-elements to style text in a particular region: text in region 1
is bigger than in other regions.
<div class=figure>
<p><img alt="Image of a complex, 3-column layout"
longdesc=regions-intro-rendering.desc src=regions-intro-rendering.png>
<p class=caption>Example rendering
</div>
<p>We assume a document fragment similar to this:
<pre>
&lt;div id=article>
&lt;h1>Introduction&lt;/h1>
&lt;p>&lt;img src="sunset" alt="">
&lt;p>This is an example…
&lt;h1>More Details&lt;/h1>
&lt;p>This illustrates…
&lt;p>Then, the example…
&lt;p>Finally, this…
&lt;/div>
</pre>
<p>The style sheet makes the DIV into a template element with five
regions, called A, *, b, c and d. The regions are grouped into two
chains: region A on its own, and the chain consisting of *, b, c and
d.
<pre>
#article {
grid: "A A c"
"A A c"
"* * c"
"a b c";
chains: * a b c }
</pre>
<p>The '*' is a special name. It indicates the <em>default slot,</em>
the slot where content goes if it doesn't have an explicit 'flow'
property. We could have used a normal letter and added an explicit
'flow' property to the children of the DIV, but by using * we don't
have to. All children thus go into region * (and continue in a, b and
c as needed). The IMG element goes into region A. We assume for
simplicity that there is only one IMG element:
<pre>#article img { flow: A }</pre>
<p>The text in region * is bolder, larger and a different color than
in the other regions. Also, an H1 that falls into this region is
rendered differently from other H1s:
<pre>
::slot(*) {
font-weight: bold;
color: #0C3D5F;
font-size: larger }
h1::slot(*) {
color: crimson;
display: run-in }
</pre>
<p>(For brevity, the example doesn't show the style rules to set the
color and background, to make the text justified, add the left border
to the second H1, etc.)
<p>As the image shows, the text of the last paragraph isn't complete
and presumably continues somewhere else, but that part is outside the
scope of this example. In paged media, we could attach the grid
template to a page instead of an element and let the text continue on
the next page; we could also make slot c into a multi-column element
so that the text forms additional columns to the right of current
image (see [[CSS3GCPM]] for some ideas), or we could allow a scrollbar
on slot c.
</div>
<!--=================================================================-->
<h3 id=dependencies>Dependencies on other modules</h3>
<p>This CSS3 module depends on the following other CSS3 modules:
<ul>
<li><cite>CSS 2.1</cite> [[!CSS21]]
&ndash; <a href="http://www.w3.org/TR/CSS21/visuren.html#block-boxes"
><dfn>block container</dfn></a> and property <dfn>content</dfn>.
<li><cite>CSS syntax module</cite> [[!CSS3SYN]] &ndash;
<dfn>interactive</dfn> vs <dfn>non-interactive</dfn> media.
<li><cite>CSS values and Units module</cite> [[!CSS3VAL]] &ndash; <a
href="/TR/css3-values#strings">
<dfn><var>&lt;string&gt;</var></dfn></a> and <a
href="/TR/css3-values#length-value">
<dfn><var>&lt;length&gt;</var></dfn></a>.
<li><cite>CSS box module</cite> [[!CSS3BOX]] &ndash; properties
<dfn>margin</dfn>, <dfn>margin-right</dfn>, <dfn>margin-left</dfn>,
<dfn>width</dfn>, <dfn>height</dfn>, <dfn>float</dfn>,
<dfn>display</dfn> and <dfn>overflow</dfn>
<li><cite>CSS text layout</cite> [[!CSS3-WRITING-MODES]] &ndash;
defines <dfn>block flow direction</dfn> and the
properties <dfn>direction</dfn> and <dfn>writing-mode</dfn>. The
latter defines when an element has a <dfn>vertical writing mode</dfn>
(text lines are vertical) or a <dfn>horizontal writing mode</dfn>
(text lines are horizontal). For brevity, we refer to the former as
a <dfn title="vertical|vertical element" >vertical element</dfn> and
to the latter as a <dfn title="horizontal|horizontal element"
>horizontal element.</dfn>
<li><cite>CSS positioning</cite> [[!CSS3POS]] &ndash; properties
<dfn>z-index</dfn>, <dfn>position</dfn>, <dfn>top</dfn>,
<dfn>right</dfn>, <dfn>bottom</dfn>, <dfn>left</dfn>.
<li><cite>CSS fragmentation</cite> [[CSS3-BREAK]] &ndash; properties
<dfn>break-before</dfn>, <dfn>break-after</dfn> and
<dfn>break-inside</dfn>; the definition of <dfn>fragmenter</dfn>.
<li><cite>CSS paged media</cite> [[CSS3PAGE]] &ndash; definition of
<dfn>page area</dfn> (in particular its width &amp; height).
<li><cite>CSS background and borders</cite> [[CSS3BG]] &ndash;
properties <dfn>background</dfn>, <dfn>background-image</dfn>,
<dfn>background-size</dfn>, <dfn>box-decoration-break</dfn>
<span class=issue>and <dfn>box-shadow</dfn>?</span>
<li& 6D50 gt;<cite>CSS tables</cite> [[!CSS3TBL]] &ndash; property
<dfn>vertical-align</dfn>. <span class=issue>[or Box Module?]</span>
<li><cite>CSS Multi-column Layout Module</cite> [[CSS3COL]] &ndash;
property <dfn>columns</dfn>.
<li><cite>CSS Fragmentation Module</cite> [[!CSS3-BREAK]] &ndash;
properties <dfn>break-before</dfn>, <dfn>break-after</dfn> and
<dfn>break-inside</dfn>.
</ul>
<p class=issue>Add to the above all the properties that are allowed on
slots (see <a href="#slot-pseudo">“The '::slot()'
pseudo-element”</a>).
<p>It has non-normative (informative) references to the following other
CSS3 modules:
<ul>
<li><cite>Selectors</cite> [[SELECT]]
</ul>
<p>See <a
href="http://www.w3.org/TR/CSS21/about.html#property-defs" >section&nbsp;1.4.2
of CSS level&nbsp;2</a> [[CSS21]] for the grammar and other notations
that this specification uses in property definitions.
<!--=================================================================-->
<h3 id=values>Values</h3>
<p>This specification follows
the <a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS
property definition conventions</a> from [[!CSS21]]. Value types not
defined in this specification are defined in CSS Level 2 Revision 1
[[!CSS21]]. Other CSS modules may expand the definitions of these
value types: for example [[CSS3COLOR]], when combined with this
module, expands the definition of the &lt;color&gt; value type as used
in this specification.</p>
<p>In addition to the property-specific values listed in their
definitions, all properties defined in this specification also accept
the <a
href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit"
>inherit</a> keyword as their property value. For readability it has
not been repeated explicitly.
<!--=================================================================-->
<h3 id=accessibility>A note about accessibility</h3>
<p><em>(This section is not normative.)</em>
<p>The facilities in this specification allow elements from a document
to be displayed in a visual order that is to a large extent
independent of the order in the document. That may have both positive
and negative effects on accessibility. The positive aspect is that it
allows the content in the document to be kept in logical order, so
that the document is as functional as possible without the style sheet
and on media where the style sheet doesn't apply. A negative aspect is
that a document that has a defined tab order (the order in which
elements get the focus when the tab-key is pressed) will show on the
screen with a tab order unrelated to the visual order. It may be
necessary to use the keyboard control features of the CSS Basic User
Interface module [[CSS3UI]] to ensure that the tab navigation follows
the visual order, or to refrain from positioning semantically related
elements in different parts of a template.
<p>The following two requirements from the Web Content Accessibility
Guidelines (WCAG) 2.0 [[WCAG20]] are particularly relevant. See that
specification for more information.
<blockquote>
<p><a
href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#content-structure-separation-sequence"
><strong>1.3.2 Meaningful Sequence:</strong></a> When the sequence in
which content is presented affects its meaning,
a <a
href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#correct-reading-sequencedef"
>correct reading sequence</a> can
be <a
href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#programmaticallydetermineddef
" >programmatically determined.</a> (Level A)
</blockquote>
<blockquote>
<p><a
href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#navigation-mechanisms-focus-order"
><strong>2.4.3 Focus Order:</strong></a> If
a <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#webpagedef"
>Web page</a> can
be <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#nav-seqdef"
>navigated sequentially</a> and the navigation sequences affect
meaning or operation, focusable components receive focus in an order
that preserves meaning and operability. (Level A)
</blockquote>
<!--=================================================================-->
<h2>Declaring templates</h2>
<p>Grid templates are declared with the 'grid-template', 'grid-rows',
'grid-columns' and 'grid' properties, defined below.
<p>An element that has a grid template is called a <dfn>grid
element.</dfn> More precisely: an element is a grid element if (1) it
generates a <span>block container box</span> [[!CSS21]] and (2) at
least one of 'grid-template', 'grid-rows' or 'grid-columns' has a
value other than the initial value.
<p class=note>Block containers are, informally, elements that can have
block elements as children, such as blocks, inline blocks or table
cells, but not inline elements or replaced elements.
<p>An element's <dfn>grid ancestor</dfn> is the nearest ancestor that
is a <span>grid element.</span>
<p class=note>Note that not all elements have a grid ancestor. E.g.,
the root element has none.
<p>The <dfn>number of columns</dfn> of a grid element is the number
of <var>&lt;col-width&gt;</var> values in 'grid-columns' or the number
of columns in 'grid-template', whichever is larger.
<p>The <dfn>number of rows</dfn> is the number
of <var>&lt;row-height&gt;</var> values in 'grid-rows' or the number
of rows in 'grid-template', whichever is larger.
<p class=note>Note that a grid element always has at least one row and one
column. Those may, however, have zero size.
<!--=================================================================-->
<h3 id=grid-template> Declaring a template: 'grid-template'</h3>
<p>The 'grid-template' property implicitly assigns a grid to an
element and defines named slots in the grid. It can also designate a
slot as the <em>default slot</em> for content without an explicit
flow.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn>grid-template</dfn>
<tr>
<th><a href="#values" >Value</a>:
<td>none | <var>&lt;string&gt;</var>+
<tr>
<th>Initial:
<td>none
<tr>
<th>Applies to:
<td><a href="http://www.w3.org/TR/CSS21/visuren.html#block-boxes"
>block container elements</a> [[!CSS21]]
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed&nbsp;value:
<td>specified value
<tr>
<th>Canonical order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p>Each string consist of one or more asterisks (“*”), letters,
periods (“.”), spaces and tabs. Each string represents one row in the
template, each symbol other than a space or tab represents one column
in that row. Spaces and tabs have no meaning. They may be added for
readability.
<p>The symbols in the template have the following meaning
<dl>
<dt>&lt;letter&gt;
<dd>
Named slot for content.
<p class=issue>CSS doesn't yet have a type corresponding to single
letter. The letters in this module are also used outside of strings
(on 'flow', e.g.), so they should be a subset of identifiers. There is
a “nmstart” macro in the grammar, but it is not exactly what we want
here. E.g., U+0300 (“combining grave accent”) is a valid first
character for an identifier, but may not be desirable as a slot in a
template. We probably want a definition based on the principle that it
is a single letter if it <em>looks</em> like a single letter. This may
correspond to the notion of <em>character cluster.</em> (There may
also be a connection with the open issue against the CSS syntax about
Unicode normalization. We want é to match é, no matter if the author
typed U+0301 U+0065 or U+00C9.)
<dt>*
<dd>
(Asterisk.) Default slot for content (explained below).
<dt>.
<dd>
(Period.) Blank space.
</dl>
<p>Multiple identical letters in adjacent rows or columns form a
single <dfn>slot</dfn> that spans those rows and columns. Ditto for
multiple “*”s. Slot names are case-sensitive, so uppercase and
lowercase letters are considered to be different letters.
<p>Non-rectangular slots and multiple slots with the same letter are
illegal. A template without any letter or “*” is illegal. A template
with more than one “*” slot is illegal. These errors cause the
declaration to be ignored.
<p class=note>Note: non-rectangular and disconnected regions may be
permitted in a future update of CSS.
<p>Rows with fewer columns than other rows are implicitly padded with
periods (“.”).
<p>Each slot (letter or “*”) acts as a block element for its contents.
<p>If the value is ''none'', then no explicit slots are defined. If
the element is a <em>grid element,</em> then the element instead has
an <dfn>implicit template</dfn> consisting of a single '*' slot.
<p class=note>Note that an element is a grid element in this case if
'grid-columns' and 'grid-rows' are not both ''auto''.
<div class=example>
<p>For example, the following two sets of style rules are equivalent:
<pre>DIV {
grid-template: none;
grid-rows: 10em 10em 10em;
grid=columns: * * * * }
</pre>
<p>and
<pre>DIV {
grid-template: "****" "****" "****";
grid-rows: 10em 10em 10em;
grid=columns: * * * * }
</pre>
</div>
<h3 id=grid-column-sizes> Specifying the widths of columns:
'grid-columns'</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn>grid-columns</dfn>
<tr>
<th><a href="#values" >Value</a>:
<td>auto | <var>&lt;col-width&gt;</var>+
<tr>
<th>Initial:
<td>auto
<tr>
<th>Applies to:
<td><span>block container</span> elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>yes, between grids with the same number of tracks
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed&nbsp;value:
<td>specified value
<tr>
<th>Canonical order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p>The 'grid-columns' property specifies the sizes of the columns of
a grid.
<p>Where
<pre class=prod>
<dfn>&lt;col-width&gt;</dfn> = <var>&lt;length&gt;</var> | <var>&lt;percentage&gt;</var> | * | <var>&lt;fraction&gt;</var> |
<var>&lt;minmax&gt;</var> | min-content | max-content | auto
<dfn>&lt;minmax&gt;</dfn> = minmax( <var>&lt;col-width&gt;</var> , <var>&lt;col-width&gt;</var> )</pre>
<p class=issue>The definition of minmax isn't correct, it should only
accepts certain values.
<p>Each <var>&lt;col-width&gt;</var> sets the width of a column, the
first value for the first column, the second for the second columns,
etc.
<p>If there are fewer <var>&lt;col-width&gt;</var> values than
the <span>number of columns</span> in the element, or if the value is
''auto'', the missing columns widths are all '*'.
<p>Each <var>&lt;col-width&gt;</var> can be one of the following:
<dl>
<dt><var>&lt;length&gt;</var>
<dd>
An explicit width for that column. Negative values are illegal.
<dt><var>&lt;fraction&gt;</var>
<dd>
(A non-negative number followed by ''fr''.) A fraction of the
remaining space, see <a href="#fraction-values-fr" >Fraction
values</a> below.
<dt>*
<dd>
(Asterisk.) All columns with a width of '*' have the same width.
<dt><var>&lt;percentage&gt;</var>
<dd>
Expresses a size as a percentage of the element's a-priori
content width. <span class=issue>When the width of the <span>grid
element</span> is dependent on content, the result is
undefined.</span>
<dt>max-content
<dt>min-content
<dd>
The column's width is determined by its contents. See
the <a href="#slot-sizes" >algorithm</a> below.
<dt>minmax(<var>p</var>,<var>q</var>)
<dd>
The column's width is constrained to be greater than or equal
to <var>p</var> and less than or equal to <var>q</var>. <var>p</var>
and <var>q</var> stand for [ <var>&lt;length&gt;</var> | max-content |
min-content | * ]. There may be white space around the <var>p</var>
and <var>q</var>. If <var>q</var> &lt; <var>p</var>, then <var>q</var>
is ignored and ''minmax(<var>p</var>,<var>q</var>)'' is treated as
'minmax(<var>p</var>,<var>p</var>)'.
<dt>auto
<dd>
Equivalent to 'minmax(min-content, max-content)'.
</dl>
<!--=================================================================-->
<h3 id=grid-row-sizes> Specifying the height of rows: 'grid-rows'</h3>