Grid

Hola, I am learning grid from mozilla docs. I am confused about this:
Now the <header> and <footer> are set to 1 / 3, which means to start at line 1 and ends at line 3.
What does it mean that we are starting at line 1 and ending at line 3, for me line == column? I defined only 2 colums 1fr 3fr, how can they use 1 / 3 which means going from 1st column to third column
.container {
font-family: sans-serif;
display: grid;
grid-template-columns: 1fr 3fr;
gap: 20px;
}
header,
footer {
border-radius: 5px;
padding: 10px;
background-color: rebeccapurple;
color: whitesmoke;
text-align: center;
}
aside {
border-right: 1px solid rebeccapurple;
}
.container {
font-family: sans-serif;
display: grid;
grid-template-columns: 1fr 3fr;
gap: 20px;
}
header,
footer {
border-radius: 5px;
padding: 10px;
background-color: rebeccapurple;
color: whitesmoke;
text-align: center;
}
aside {
border-right: 1px solid rebeccapurple;
}
header {
grid-column: 1 / 3;
grid-row: 1;
}
main {
grid-column: 2;
grid-row: 2;
}
aside {
grid-column: 1;
grid-row: 2;
}
footer {
grid-column: 1 / 3;
grid-row: 3;
}
header {
grid-column: 1 / 3;
grid-row: 1;
}
main {
grid-column: 2;
grid-row: 2;
}
aside {
grid-column: 1;
grid-row: 2;
}
footer {
grid-column: 1 / 3;
grid-row: 3;
}
43 Replies
brr
brrOP3mo ago
MDN Web Docs
CSS grid layout - Learn web development | MDN
CSS grid layout is a two-dimensional layout system for the web. It lets you organize content into rows and columns and offers many features to simplify the creation of complex layouts. This article will explain all you need to know to get started with grid layout.
ἔρως
ἔρως3mo ago
a "line" is a row
brr
brrOP3mo ago
Does 1 / 3 means that even though there are 2 colums i.e. 1fr and 3fr, it will automatically make 3 columns in it ehh
ἔρως
ἔρως3mo ago
a row ocupies multiple columns
brr
brrOP3mo ago
No description
ἔρως
ἔρως3mo ago
for me line == column?
brr
brrOP3mo ago
No description
ἔρως
ἔρως3mo ago
this is wrong
b1mind
b1mind3mo ago
best way to learn this is open dev tools and use the grid highlight
brr
brrOP3mo ago
how is header going from line 1 to 3 here doesnt look like a row to me
b1mind
b1mind3mo ago
Best way to write that is grid areas not lines 🥲
brr
brrOP3mo ago
im using that below the article but i dont undertand this
ἔρως
ἔρως3mo ago
it goes from column 1 to column 2, but ends before column 3
b1mind
b1mind3mo ago
Why not use it here then?
brr
brrOP3mo ago
thanks for the tip mhm currently using it but i want to understand this property
Jochem
Jochem3mo ago
if you look at this grid, those numbers represent the lines between the grid cells. That's a 3x3 grid, and 1 / 3 runs from 1 on the left to 3 on the right
No description
brr
brrOP3mo ago
problem is i have only 2 columns
b1mind
b1mind3mo ago
ya so much easier to see witch grid tools
brr
brrOP3mo ago
in the screenshot*
b1mind
b1mind3mo ago
yes but two columns makes 3 tracks
brr
brrOP3mo ago
if there were 3 i would understand
b1mind
b1mind3mo ago
lets use "tracks" instead of lines too EPic
Jochem
Jochem3mo ago
then just pretend the third column isn't there. Three columns make for 4 lines, two columns make for 3 lines
brr
brrOP3mo ago
mhmm it kinda makes sense
b1mind
b1mind3mo ago
tracks
Jochem
Jochem3mo ago
one cell has a left border, and a right border. If you have two cells, there's a left, a middle, and a right.
b1mind
b1mind3mo ago
not lines xD
brr
brrOP3mo ago
mhmm kinda understand thank you i wont use this proprty much so i think i have enoguh undertanding
b1mind
b1mind3mo ago
use it all over Grid ❤️
ἔρως
ἔρως3mo ago
that property is the shorthand for grid-column-start and grid-column-end
Jochem
Jochem3mo ago
I prefer using named areas personally
brr
brrOP3mo ago
oh okay i wonder why we cant use 1/2
ἔρως
ἔρως3mo ago
you can
b1mind
b1mind3mo ago
you can
ἔρως
ἔρως3mo ago
but you're saying to start at 1 and end before 2
b1mind
b1mind3mo ago
jinx
ἔρως
ἔρως3mo ago
so, it's the same column
Jochem
Jochem3mo ago
1 / 2 just means the first cell. The numbers refer to the tracks, not the colmns
ἔρως
ἔρως3mo ago
nothing changes
Jochem
Jochem3mo ago
and one column has two tracks one on the left, one on the right it might help to draw a 2x2 grid on a piece of paper. You end up drawing three vertical lines and three horizontal, but end up with two columns and two rows you just number the lines left to right for the grid-column property's value. And yes, it's honestly not the best name for the property, because it's called column but refers the tracks. just think that it defines what the column is rather than which column it is
b1mind
b1mind3mo ago
same with row and yes you can assign more on the child and it will make more cols/rows with auto
ἔρως
ἔρως3mo ago
in short, your are starting from track 1 and it goes until track 3
brr
brrOP3mo ago
thank you everyone!

Did you find this page helpful?