Briefly
A shortcut for the properties grid
, grid
. It allows you to write all values in one line. The main thing is not to get confused when reading afterward 😅
Example
Four rows of 150 pixels and three columns will be created: 1fr, 200 pixels, and 1fr in size:
.container { display: grid; grid-template: repeat(4, 150px) / 1fr 200px 1fr;}
.container { display: grid; grid-template: repeat(4, 150px) / 1fr 200px 1fr; }
How to write
You can specify all columns and rows at once, separating them with a slash /
. Rows come first, followed by columns, don't mix them up!
Use all available values for the properties grid
and grid
, separating them with a slash.
Tips
- Chrome 66, поддерживается
- Edge 79, поддерживается
- Firefox 76, поддерживается
- Safari 12.1, поддерживается
In practice
Advice 1
🛠 In this same property, you can also set the value for grid
. But in my opinion, then the code turns into a mess and becomes completely unreadable. It’s better to use this property separately:
Better like this?
.container { display: grid; grid-template: [row1-start] "header header header" 25px [row1-end] [row2-start] "footer footer footer" 25px [row2-end] / auto 50px auto;}
.container { display: grid; grid-template: [row1-start] "header header header" 25px [row1-end] [row2-start] "footer footer footer" 25px [row2-end] / auto 50px auto; }
Or like this?
.container { display: grid; grid-template: [row1-start] 25px [row1-end] [row2-start] 25px [row2-end] / auto 50px auto; grid-template-areas: "header header header" "footer footer footer";}
.container { display: grid; grid-template: [row1-start] 25px [row1-end] [row2-start] 25px [row2-end] / auto 50px auto; grid-template-areas: "header header header" "footer footer footer"; }
But there is a technical possibility, it’s up to you! 😉