This page contains material to facilitate discussion of issues surrounding the CSS3 Grid Layout module.
Link to current Working Draft:http://www.w3.org/TR/css3-grid-layout/
Link to current Editor's draft: http://dev.w3.org/csswg/css3-grid-align/
Example showing named areas versus named lines:
<!-- Named areas using template property --> <style type="text/css"> @media (orientation: portrait) { #grid { display: grid; /* The rows, columns and areas of the grid are defined visually using the */ /* grid-template property. Each string is a row, and each word an area. */ /* The number of words in a string determines the number of */ /* columns. Note the number of words in each string must be identical. */ grid-template: "title stats" "score stats" "board board" "ctrls ctrls"; /* Columns and rows created with the template property can be assigned a sizing */ /* function with the grid-definition-columns and grid-definition-rows properties. */ grid-definition-columns: auto minmax(min-content, 1fr); grid-definition-rows: auto auto minmax(min-content, 1fr) auto } } @media (orientation: landscape) { #grid { display: grid; /* Again the template property defines areas of the same name, but this time */ /* positioned differently to better suit a landscape orientation. */ grid-template: "title board" "stats board" "score ctrls"; grid-definition-columns: auto minmax(min-content, 1fr); grid-definition-rows: auto minmax(min-content, 1fr) auto } } /* The grid-area property places a grid item into named region (area) of the grid. */ #title { grid-area: title } #score { grid-area: score } #stats { grid-area: stats } #board { grid-area: board } #controls { grid-area: ctrls } </style> <div id="grid"> <div id="title">Game Title</div> <div id="score">Score</div> <div id="stats">Stats</div> <div id="board">Board</div> <div id="controls">Controls</div> </div>
<!-- Same markup using named line syntax instead --> <style type="text/css"> @media (orientation: portrait) { #grid { display: grid; grid-definition-columns: "board-start" "ctrls-start" "title-start" "score-start" auto "title-end" "score-end" "stats-start" minmax(min-content, 1fr) "stats-end" "board-end" "ctrls-end"; grid-definition-rows: "title-head" "stats-head" auto "title-foot" "score-head" auto "score-foot" "stats-foot" "board-head" minmax(min-content, 1fr) "board-foot" "ctrls-head" auto "ctrls-foot" } } @media (orientation: landscape) { #grid { display: grid; grid-definition-columns: "title-start" "stats-start" "score-start" auto "title-end" "stats-end" "score-end" "board-start" "ctrls-start" minmax(min-content, 1fr) "board-end" "ctrls-end"; grid-definition-rows: "title-head" "board-head" auto "title-foot" "stats-head" auto "stats-foot" "board-foot" "score-head" "ctrls-head" minmax(min-content, 1fr) "score-foot" "ctrls-foot" } } /* The grid-area property places a grid item into region of the grid identified by */ /* top, right, bottom and left grid lines. */ #title { grid-area: "title-head" "title-end" "title-foot" "title-start"} #score { grid-area: "score-head" "score-end" "score-foot" "score-start" } #stats { grid-area: "stats-head" "stats-end" "stats-foot" "stats-start" } #board { grid-area: "board-head" "board-end" "board-foot" "board-start" } #controls { grid-area: "ctrls-head" "ctrls-end" "ctrls-foot" "ctrls-start" } </style> <div id="grid"> <div id="title">Game Title</div> <div id="score">Score</div> <div id="stats">Stats</div> <div id="board">Board</div> <div id="controls">Controls</div> </div>
Latest ED incorporates text from latest Flexbox draft. Given the code below:
<div id=”container” style=”display: grid”> Text before <div id=”gridItem”>Grid item</div> Text after </div>
<head> <style> #container{display:grid; grid-auto-flow:columns;} label{grid-column: 1;} input{grid-column: 2;} </style> </head> <body> <form id=”container” style=”display: grid”> <ul> <li> <label id="label1">Input 1</label> <input type="text" id="input1"> </li> <li> <label id="label2">Input 2</label> <input type="text" id="input2"> </li> <li> <label id="label3">Input 3</label> <input type="text" id="input3"> </li> </ul> </form> </body>
Proposal is to postpone positioning of descendant grid item until level 2, when this issue can be more fully worked through. We could instead make it our mission to make the current spec future compatible with what we anticipate level 2 to contain.
Three scenarios where boxes are stretch aligned that we could make agree in their behavior (or not):
In each of these cases we satisfy the equation:
margin_size1 + border_size1 + padding_size1 + box_size + padding_size2 + border_size2 + margin_size2 == space afforded to item by parent container
When both margins are auto though, and the box is larger than the space afforded to it by its container, a paragraph of section 9.3 for css3-box http://www.w3.org/TR/css3-box/#blockwidth says:
If ‘width’ is not ‘auto’ and ‘border-left-width’ + ‘padding-left’ + ‘width’ + ‘padding-right’ + ‘border-right-width’ + scrollbar width (if any) (plus any of ‘margin-left’ or ‘margin-right’ that are not ‘auto’) is larger than the width of the containing block, then any ‘auto’ values for ‘margin-left’ or ‘margin-right’ are, for the following rules, treated as zero. We should drop this paragraph. It causes blocks that are wider than their parent not to be centered (unlike blocks that are narrower), which looks strange.
The Grid ignores the paragraph above as suggested so that two auto margins will always result in a centered item whenever width/height is not auto. I noticed that Flexbox keeps the last sentence per its example 10 in the latest ED http://dev.w3.org/csswg/css3-flexbox/#auto-margins.
Options:
The first option works well with auto-positioning while the second would require the author to write a (trivial) rule to declare that all elements are in fact grid items: #grid > * { grid-area: auto; } The second option could be used position descendants of the grid in addition to just children, but breaks from the pattern established by flexbox and would differ from IE's current implementation.
We have four leaf level properties and five proposed shorthands. Are we overdoing it? See table below from Hamburg F2F.
grid-area | grid-column | grid-row |
---|---|---|
grid-position | grid-column-position | grid-row-position |
grid-span | grid-column-span | grid-row-span |
=
C R ΔC ΔR | C ΔC | R ΔR |
---|---|---|
C R | C | R |
ΔC ΔR | ΔC | ΔR |
Grid-layer vs. z-index property for Grid
Grid-layer is currently used to control the stacking of grid items in a grid element; one example of this that is mentioned in the current Editor's Draft would be using Grid to build a range control where the “thumb” of the control is displayed on top of the underlying track. However, grid-layer is in many ways similar to the existing z-index property. Is a separate property needed, or can z-index replace the grid-layer property?
We have three primary goals w/r/t stacking Grid Items:
Z-index should be used to replace the grid-layer property (i.e. z-index applies to statically-positioned Grid Items.) Specifically, in cases where Grid Items overlap, z-index provides control over the drawing order of Grid Items. Both Grid elements and Grid Items generate a stacking context as described for floats (step 5, section 14) in the CSS3 Box Model.
Note also that using z-index in place of grid-layer has been previously discussed on the www-styling mailing list.
Fractional-track sizing algorithm update
The grid-sizing algorithm introduced in the previous Editor's Draft did not define the expected behavior for sizing a fractionally-sized track (e.g. 1fr, 2fr,…) when a Grid Element was shrink-to-fit. This should be addressed so that future implementations of Grid Layout behave predictably across platforms.
We propose to modify the existing grid sizing algorithm as follows: if the Grid Element is shrink-to-fit, then we set the size of a fractional track (i.e. determine the size of a '1fr' track) by making sure that 1) the proportions of all fractional tracks are preserved (e.g. a '1fr' track is half the size of a '2fr' track) and 2) fractional tracks are large enough contain all Grid Items that span them. If the Grid Element is not shrink-to-fit, then the algorithm follows its current path. The specific algorithm updates can be found in step 6 of the updated Editor's Draft.