我试图让网格列跨越每个行,包括隐式行。
我遇到this question询问如何跨越所有网格行。第二个答案有一个更正说明更好的解决方案。这似乎可行,但我自己的例子和第二个答案的评论表明它不起作用。
W3 spec也给出了一个非常接近的例子。
我的代码有问题,或者这可能是Firefox,Chrome,和 Safari中的错误?
I also have this example in a CodePen here
* {
box-sizing: border-box;
}
.container {
border: 1px solid #666;
max-width: 1000px;
padding: 10px;
display: grid;
grid-template-columns: 150px 1fr 300px;
/* grid-template-rows: repeat(auto) [rows-end]; Doesn't seem to help */
/* grid-template-rows: [rows-start] repeat(auto) [rows-end]; Doesn't seem to help */
grid-template-rows: repeat(auto);
grid-gap: 10px;
margin: 10px auto;
grid-auto-flow: row dense;
/* justify-items: stretch; */
/* align-items: stretch; */
}
.container>* {
grid-column: 2 / 3;
padding: 10px;
outline: 1px solid #666;
}
.pop {
grid-column: 1 / 2;
/* grid-column: 1 / -1; If I switch to this, this div will span the full width of the grid, which is exactly what I'm trying to do with rows*/
}
.tertiary {
grid-column: 1 / 2;
}
.secondary {
grid-column: 3 / 3;
grid-row: 1 / -1;
/* Doesn't work */
/* grid-row: rows-start / rows-end; Doesn't work */
/* grid-row: 1 / rows-end; Also doesn't work */
/* grid-row: 1 / span 7; This works, but I need to span an unknown number of rows*/
/* grid-row: 1 / span 99; This is gross and creates 99 rows */
}

<div class="container">
<div class="secondary">Secondary - why doesn't this span all the way to the bottom of the grid?</div>
<div class="tertiary">Tertiary</div>
<div class="tertiary">Tertiary</div>
<div class="tertiary">Tertiary</div>
<div>Primary</div>
<div>Primary</div>
<div>Primary</div>
<div class="pop">Span tertiary and primary</div>
<div>Primary</div>
<div class="tertiary">Tertiary</div>
<div>Primary</div>
<div>Primary</div>
</div>
&#13;
答案 0 :(得分:2)
你的方式有两个障碍。
首先,def isunique(string):
return all(string.count(i)==1 for i in string if i!=' ')
规则中的这一行CSS代码:
.container
此代码无效。 grid-template-rows: repeat(auto);
表示法中的参数必须以正整数开头,该整数指定重复次数。你没有这个,所以代码不起作用。 spec。
其次,即使上面的代码是正确的,让我们说:
repeat()
您的专栏仍然不会跨越所有行。
这是因为,正如您在the other answer you cited中看到的那样,可以将轨道定义设置为仅在显式网格中覆盖所有垂直轨道。
所以这会奏效:
grid-auto-rows: auto; (which happens to be the default setting anyway)
the other answer you cited中详细介绍了问题的其余部分。