Naming line wen definig a grid
One
Two
Three
Four
[main-star]
[content-start]
[content-end]
[main-end]
[main-start]
[content-start]
[content-end]
[main-end]
#container-1 { display: grid; grid-template-columns: [main-start] 1fr [content-start] 1fr [content-end] 1fr [main-end]; grid-template-rows: [main-start] 100px [content-start] 100px [content-end] 100px [main-end]; } #boxOne { grid-column-start:main-start; grid-row-start:main-start; grid-row-end:main-end; } #boxTwo { grid-column-start:content-end; grid-row-start:main-start; grid-row-end:content-end; } #boxThree { grid-column-start:content-start; grid-row-start:main-start; } #boxFour { grid-column-start:content-start; grid-column-end:main-end; grid-row-start:content-end; }
Implicit grid areas from named lines
aside.
[main-start aside-start]
[aside-end content-start]
[content-end]
[main-end]
[main-start aside-start]
[content-start]
[content-end]
[aside-end main-end]
#wrapper { display: grid; grid-template-columns: [main-start aside-start] 1fr [aside-end content-start] 1fr [content-end] 1fr [main-end]; grid-template-rows: [main-start aside-start] 100px [content-start] 100px [content-end] 100px [aside-end main-end]; } .thing { grid-area: content; } .aside { grid-area: aside; }
Implicit Grid lines from named areas
hd-start
sd-start
ft-start
main-start
sd-end
hd-end
main-end
ft-end
hd-start
hd-end
sd-start
main-start
ft-start
main-end
sd-end
ft-end
#wrapper { display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,100px); grid-template-areas: "hd hd hd" "sd main --" "ft ft ft"; } .overlay{ grid-column: main-start / hd-end; grid-row: hd-start / ft-end; }
Multiple lines with the same name with repeat()
How our items are placed against these lines.
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
[col-start]
#wrapper { display: grid; grid-template-columns: repeat(12, [col-start] 1fr); } .item1 { grid-column: col-start / col-start 5; } .item2 { grid-column: col-start 7 / span 3; }
Column named col1-start followed by column named col2-start,that is being repeated.
1fr
2fr
[col1-start]
[col2-start]
[col1-start 2]
[col2-start 2]
[col1-start 3]
[col2-start 3]
[col1-start 4]
[col2-start 4]
#wrapper { display: grid; grid-template-columns: repeat(4, [col1-start] 1fr [col2-start] 2fr); } .item1 { grid-column: col1-start ; } .item2 { grid-column: col2-start ; } .item3 { grid-column: col1-start 2; .item4 { grid-column: col2-start 2 / col2-start 4 ; }
The tracks as giving a line multiple names, which each have a start and end line.
col-start 2 / col-end 6
col-start 1 / col-end
col-start 3 / span 3 col-end
[col-start]
[col-end 1 / col-start 2]
[col-end 2 / col-start 3]
[col-end 3 / col-start 4]
[col-end 4 / col-start 5]
[col-end 5 / col-start 6]
[col-end 6]
#wrapper { display: grid; grid-template-columns: repeat(4, [col1-start] 1fr [col2-start] 2fr); } .item1 { grid-column: col1-start ; } .item2 { grid-column: col2-start ; } .item3 { grid-column: col1-start 2;
We can then use that framework to layout our page. For example, to create a three column layout with a header and footer, I might
have the following markup.
[col-start]
[col-start 4]
[col-start 10]
#wrapper { display: grid; grid-gap: 10px; grid-template-columns: repeat(12, [col-start] 1fr); } header,footer { grid-column: col-start / span 12; background-color: rgba(255,153,153,.3); } aside.side1 { grid-column: col-start / span 3; grid-row: 2; background-color: rgba(153,102,204,.2); } article { grid-column: col-start 4 / span 6; grid-row: 2; background-color: rgba(255,53,153,.2); } aside.side2 { grid-column: col-start 10 / span 3; grid-row: 2; background-color: rgba(153,102,204,.2); }