This question is about whether CSS grid "span counting" -- whether it should start on implicit grid line. In CSS Definitive Guide, 4th Ed, p. 695, it is said that
box4 is where things really get interesting. It ends on the fifth row line, which is to say the second implicit grid line. It spans back three lines—and yet, it still starts on the same grid line as box3. This happens because spans have to start counting within the explicit grid. Once they start, they can continue on into the implicit grid (as happened with box2), but they cannot start counting within the implicit grid.
Is it true? Or has there been a spec change? Can "span counting" start within implicit grid?
It is a bit confusing as the code in the book used:
.box04 {grid-column: 4; grid-row: span 2 / 5;}
while the online code on Github.com used:
.box04 {grid-column: 4; grid-row: span 4 / 5;}
(so I do see it start counting at row grid line 5, and start counting 4 steps back starting at this implicit grid line 5, and the rule is "we shouldn't start counting at implicit grid lines". So has the rule changed or the rule doesn't mean it that way?).
and in order to have the result as on the book, it needs to be 4 / 5
instead of 2 / 5
, and the text in the book said "spans back three lines" -- shouldn't it be span back 4 or 2 lines? If we can't count implicit grid, then really it should be 2 / 5
, but if we can count implicit grid, then it should be 4 / 5
. So was there a spec change? And the "three lines" probably is a typo? So if we need to span 4, then that probably means we count starting on either implicit or explicit grid line?
The code is a bit long but we can just look at box04
:
html {
background: #DDD;
}
body {
padding: 2em;
margin: 0;
box-sizing: border-box;
background: white;
}
ul.grid {
padding: 0;
margin: 0;
}
.grid.boxed {
border: 1px solid black;
}
.grid.boxed.lines {
padding: 1px 0 0 1px;
}
.grid.small *[class^="box"] {
font-size: 1em;
font-weight: normal;
padding: 0.25em;
border-width: 0.167em;
}
*[class^="box"] {
border: 0.33em solid;
font: bold 2em Arvo, sans-serif;
display: flex;
align-items: center;
justify-content: center;
}
*[class^="box"][class*="01"] {
color: rgb(255, 0, 0);
background: rgba(255, 0, 0, 0.1);
}
*[class^="box"][class*="02"] {
color: rgb(255, 128, 0);
background: rgba(255, 128, 0, 0.15);
}
*[class^="box"][class*="03"] {
color: rgb(216, 168, 0);
background: rgba(216, 168, 0, 0.2);
}
*[class^="box"][class*="04"] {
color: rgb(0, 128, 0);
background: rgba(0, 128, 0, 0.1);
}
*[class^="box"][class*="05"] {
color: rgb(0, 0, 255);
background: rgba(0, 0, 255, 0.1);
}
*[class^="box"][class*="06"] {
color: rgb(128, 0, 128);
background: rgba(128, 0, 128, 0.1);
}
span[class*="gridline"] {
border: 1px dashed;
margin: -1px 0 0 -1px;
}
/* for print preview/production
body:hover {filter: saturate(0%);}
*/
#grid {
grid-auto-rows: 2em;
grid-auto-columns: 5em;
width: 35em;
}
#grid {
display: grid;
grid-template-rows: 2em 2em;
grid-template-columns: repeat(6, 4em);
}
.box01 {
grid-column: 1;
grid-row: 1 / 4;
}
.box02 {
grid-column: 2;
grid-row: 3 / span 2;
}
.box03 {
grid-column: 3;
grid-row: span 2 / 3;
}
.box04 {
grid-column: 4;
grid-row: span 4 / 5;
}
.box05 {
grid-column: 5;
grid-row: span 6 / 5;
}
.box06 {
grid-column: 6;
grid-row: -1 / span 3;
}
.box07 {
grid-column: 7;
grid-row: span 3 / -1;
}
span[class*="box"] {
z-index: 1;
}
span.explicit {
background: #DDD;
grid-area: 1 / 1 / 3 / 7;
}
<div class="grid gridlines" id="grid">
<span class="box01">1</span>
<span class="box02">2</span>
<span class="box03">3</span>
<span class="box04">4</span>
<span class="box05">5</span>
<span class="box06">6</span>
<span class="box07">7</span>
<span class="explicit"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
<span class="gridlines"></span>
</div>