search

Home  >  Q&A  >  body text

Can grid-template-rows: Repeat(auto-fill, 80px) be used interchangeably with grid-auto-rows: 80px?

I want the grid to add more rows as needed when adding dynamic content.

This will solve the problem:

.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;
}

I want to know if I can use grid-template-rows:repeat(auto-fill, 80px); instead of grid-auto-rows: 80px?

P粉823268006P粉823268006487 days ago563

reply all(1)I'll reply

  • P粉627136450

    P粉6271364502023-09-13 13:02:46

    Well, grid-template-rows: Repeat(auto-fill, 80px); is according to the spec, but it doesn't give the desired result. Instead, it just creates an explicit row with a height of 80 pixels, and the other rows resize automatically.

    However, since you want to add rows as needed, i.e. implicitly created grid rows, you should use grid-auto-rows and there is no need to use grid -template-rows. < /p>

    .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>

    reply
    0
  • Cancelreply