grid-template-rows: Repeat(auto-fill, 80px) 可以與 grid-auto-rows: 80px 互換使用嗎?
P粉823268006
P粉823268006 2023-09-12 21:10:45
0
1
470

我希望網格在添加動態內容時根據需要添加更多行。

這就能解決問題:

.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

P粉823268006
P粉823268006

全部回覆(1)
P粉627136450

嗯,grid-template-rows: Repeat(auto-fill, 80px); 是根據 規格,但它沒有給出所需的結果。相反,它只是創建一個高度為 80 像素的顯式行,並且其他行會自動調整大小。

但是,由於您希望根據需要添加行,即隱式創建的網格行,因此您應該使用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>
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!