css 可以grid-template-rows:repeat(auto-fill,80 px)可以与grid-auto-rows互换使用:80px?

nfeuvbwi  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(119)

我希望网格在添加动态内容时根据需要添加更多行。
这就是诀窍:

.grid {
  display: grid;
  grid-template-rows: 80px;
  grid-auto-rows: 80px;
//  grid-template-rows: repeat(auto-fill, 80px);
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  grid-gap: 60px 60px;
}

我想知道我们是否可以使用grid-template-rows: repeat(auto-fill, 80px);来代替grid-auto-rows: 80px

cgfeq70w

cgfeq70w1#

根据规范,grid-template-rows: repeat(auto-fill, 80px);是一个有效的声明,但它没有给予预期的结果。相反,它只创建一个高度为80px的显式行,其他行的大小是自动调整的。
但是,由于您希望根据需要添加行,即隐式创建的网格行,您应该使用grid-auto-rows,而不需要使用grid-template-rows

.grid {
  display: grid;
  grid-auto-rows: 80px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 60px;
  }

.grid div {
  background-color: silver;
}
<div class="grid">
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
</div>

相关问题