2
我正在嘗試製作一個網格列跨度爲,每行行,包括隱式行。在CSS Grid中創建所有行(包括隱含行)的列跨度
我碰到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>
感謝您澄清無效行代碼。所以我回到了我的實際原始需求 - 是否有一種方法可以讓第三列一直延伸到底部,當有*未知*行數時? – freshyill
是的,這個問題是在另一篇文章中探討的。這是迄今爲止社區使用純CSS所提出的最好的方法。在網格佈局中似乎沒有一個乾淨的方法。 –
或者,您可以直接定位柵格項目:https://stackoverflow.com/q/46308048/3597276 –