I need to understand grid template rules
The container grid template only have 13 columns and on the banner grid area shows 14 instead of 13, but when I change it to 13, it does not spread to the full width of the page. so if I change it to 14 it will extend to the full length of the page, but why? and it does make sense since like i mentioned there is only 13 columns, pls help me understand this ty
10 Replies
to assign a child to a grid area, the value you use are the 'grid-lines' not the cell itself.
example: here you have 3 columns, but 4 lines (
|
) and 2 rows, but 3 lines ---
there is always 1 line more then the amount of colls/rows
in this case the item 2
is placed at
- grid-row-start: 1
- grid-col-start: 2
- grid-row-end: 2
- grid-col-end 3
so: grid-area: 1 / 2 / 2 / 3
off-topic tip: if you want multiple columns/rows of the same size. you can use the repeat() function. repeat(13, 1fr)
I don't want to confuse you too much, but you can also use negative numbers for grid lines (these will be counted from the right and bottom).
because you can combine the positive and negative lines numbers, you can take advantage of that.
For example, if you want to span an item from the first to the last column. you can do: 1 / -1
so your banner:
grid-area: 1 / 1 / 3 / -1;
so to make it clear, if i were to write this
it would be grid-template: 1fr 1fr / 1fr 1fr 1fr and if i want to cover the whole top page, i would have to use
it would be grid-template: 1fr 1fr / 1fr 1fr 1fr and if i want to cover the whole top page, i would have to use
the whole top row would be
(the first row ends at grid line 2)
or
(-1 is the first grid line from the right, effectively the last)
but you can also divide the grid-area in grid-row and grid-column
maybe this is more clear in the usage
tahnks for the help also i want to ask is there a way that I can use anotehr css grid-template in another css file
Keep in mind that if you need to affect a lot of elements you should use grid-template-area
you mean like
also my previous question, can i use a grid template from one css file to another css file
What do you mean?
like
if i want o start another file
but use the grid template that i already setup in another file
can css do that
Css doesn't care about files, as long as everything is loaded in the browser on the page you want to use the stuff in, it works
Maybe you should look up some more basic stuff about how css works before trying to use complex stuff like grid or flex or the like
its just some thought on my mid as i work on my projecxt
but thanks