Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat grid-template-rows for all rows

Tags:

css

css-grid

I'm trying create template for rows in my grid block:

grid-template-rows: repeat(3, 150px); 

I know, this template should be work for first 3 rows. However, from 4 row this template is not work.
Can i make template for all rows?

P.S. This template work only for 1st row.

grid-template-rows: 150px; 
like image 408
Dmitriy Doronin Avatar asked Jul 31 '17 09:07

Dmitriy Doronin


People also ask

How do I use grid-template-columns to repeat?

grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); This way, we get a repeating number of columns (thanks to repeat() ) that will fill all of the available space of the grid (thanks to auto-fit ) while never shrinking narrower than 250px and each taking up an equal fraction of space (thanks to minmax() ).

Can you use repeat in grid template areas?

You can also use the shorthand repeat code like above to make the columns repeat. For example, “grid-template-columns:repeat (9, 1fr);” shows the combined commands that specify the fraction code and the number of columns.

What does grid-template-rows Auto do?

auto. The auto keyword behaves similarly to minmax(min-content, max-content) in most cases. Since auto track sizes can be stretched by the align-content and justify-content properties, they will take up any remaining space in the grid container by default auto -matically.


1 Answers

Use grid-auto-rows (automatically generated rows) instead of grid-template-rows (manually generated rows). In current case grid-auto-rows: 150px will do the trick. Demo:

.grid {    display: grid;    grid-auto-rows: 150px;    /* space between columns for demo */    grid-gap: 10px;  }    /* just styles for demo */  .grid__item {    background-color: tomato;    color: white;  }
<div class="grid">    <div class="grid__item">One</div>    <div class="grid__item">Two</div>    <div class="grid__item">Three</div>    <div class="grid__item">Four</div>    <div class="grid__item">Five</div>    <div class="grid__item">Six</div>    <div class="grid__item">Seven</div>    <div class="grid__item">Eight</div>    <div class="grid__item">Nine</div>  </div>
like image 197
Vadim Ovchinnikov Avatar answered Sep 28 '22 06:09

Vadim Ovchinnikov