Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,430 --> 00:00:03,810
Now that you know some of the fundamentals
2
00:00:03,810 --> 00:00:07,540
of CSS Grid in practice, let's now also learn
3
00:00:07,540 --> 00:00:09,123
some theory about it.
4
00:00:10,380 --> 00:00:12,760
And so just like with flexbox,
5
00:00:12,760 --> 00:00:17,760
the first question that we ask is what actually is CSS Grid?
6
00:00:18,180 --> 00:00:21,570
And at the most basic level CSS Grid
7
00:00:21,570 --> 00:00:26,370
is a set of CSS properties that web developers can use
8
00:00:26,370 --> 00:00:29,640
to build two dimensional layouts.
9
00:00:29,640 --> 00:00:32,740
And when CSS Grid was first developed
10
00:00:32,740 --> 00:00:36,270
and brought into browsers a couple of years ago,
11
00:00:36,270 --> 00:00:39,220
the main idea behind it was that now
12
00:00:39,220 --> 00:00:42,850
we could divide a container element into rows
13
00:00:42,850 --> 00:00:47,850
and columns that we could then fill with its child elements.
14
00:00:48,010 --> 00:00:51,270
And a lot of stuff is possible here.
15
00:00:51,270 --> 00:00:55,020
So things like spending elements across multiple rows
16
00:00:55,020 --> 00:01:00,020
and columns, overlap different elements and more.
17
00:01:00,210 --> 00:01:03,980
So we use CSS Grid in two dimensional contexts
18
00:01:03,980 --> 00:01:08,150
where it allows us to write a lot less nested HTML,
19
00:01:08,150 --> 00:01:10,980
and also easier to read CSS.
20
00:01:10,980 --> 00:01:12,950
And you will start appreciating
21
00:01:12,950 --> 00:01:16,030
these characteristics of CSS Grid
22
00:01:16,030 --> 00:01:18,100
once you actually start using it
23
00:01:18,100 --> 00:01:21,390
and maybe comparing it to things like flexbox
24
00:01:21,390 --> 00:01:24,000
or even float layouts.
25
00:01:24,000 --> 00:01:27,043
So CSS Grid completely changes the way
26
00:01:27,043 --> 00:01:32,043
that we envision and build two dimensional layouts with CSS.
27
00:01:32,430 --> 00:01:35,710
And therefore we can say that in a way,
28
00:01:35,710 --> 00:01:40,140
CSS Grid completely revolutionized CSS.
29
00:01:40,140 --> 00:01:41,930
Now one common misconception
30
00:01:41,930 --> 00:01:45,650
that many beginners have is that CSS Grid
31
00:01:45,650 --> 00:01:48,590
is meant to replace flexbox.
32
00:01:48,590 --> 00:01:51,960
However, that is really not the case.
33
00:01:51,960 --> 00:01:56,960
So instead flexbox and CSS Grid work together perfectly.
34
00:01:57,650 --> 00:02:00,830
You simply use them in different situations.
35
00:02:00,830 --> 00:02:03,420
So when you need a one dimensional layout,
36
00:02:03,420 --> 00:02:06,610
then you can simply reach for flexbox.
37
00:02:06,610 --> 00:02:09,330
But if you need a two dimensional layout,
38
00:02:09,330 --> 00:02:11,730
which is usually a grid anyway,
39
00:02:11,730 --> 00:02:15,370
then you can use CSS Grid for that.
40
00:02:15,370 --> 00:02:18,510
So again, one does not replace the other,
41
00:02:18,510 --> 00:02:21,623
but instead they work together really nicely.
42
00:02:23,750 --> 00:02:25,730
And now we need to once again,
43
00:02:25,730 --> 00:02:28,090
talk about some terminology here
44
00:02:28,090 --> 00:02:30,620
so that when I talk about CSS Grid,
45
00:02:30,620 --> 00:02:33,220
we are all on the same page here.
46
00:02:33,220 --> 00:02:36,060
So as we just learned already actually
47
00:02:36,060 --> 00:02:40,130
the grid container is basically where everything happens
48
00:02:40,130 --> 00:02:42,230
and we create a grid container
49
00:02:42,230 --> 00:02:45,353
by setting its display property to grid.
50
00:02:46,200 --> 00:02:49,580
Then all the child elements of the grid container
51
00:02:49,580 --> 00:02:52,330
will be the gid items.
52
00:02:52,330 --> 00:02:54,840
So again, just like we learned before,
53
00:02:54,840 --> 00:02:59,223
and also this is quite similar to flexbox, right?
54
00:03:00,060 --> 00:03:04,120
Then also like flexbox we also have axis here.
55
00:03:04,120 --> 00:03:08,550
So we have a row axis and a column axis.
56
00:03:08,550 --> 00:03:12,140
Now, unlike flexbox we cannot change the direction
57
00:03:12,140 --> 00:03:14,890
of the row and the column axis,
58
00:03:14,890 --> 00:03:18,330
which in my opinion actually makes it even a bit easier
59
00:03:18,330 --> 00:03:20,433
to work with CSS Grid.
60
00:03:21,350 --> 00:03:26,350
All right, so this is the basic terminology about CSS Grid.
61
00:03:27,200 --> 00:03:29,870
However, since two dimensional layouts
62
00:03:29,870 --> 00:03:31,600
are a bit more complex,
63
00:03:31,600 --> 00:03:34,270
we need actually some more terminology
64
00:03:34,270 --> 00:03:37,720
in order to really understand what's going on.
65
00:03:37,720 --> 00:03:41,220
So let's look at some more terminology here.
66
00:03:41,220 --> 00:03:43,980
So this is what we just saw before,
67
00:03:43,980 --> 00:03:48,050
but now let's also introduce the concept of grid lines,
68
00:03:48,050 --> 00:03:49,580
which are these lines,
69
00:03:49,580 --> 00:03:51,860
which basically divide up the grid
70
00:03:51,860 --> 00:03:54,910
and separate the columns and the rows.
71
00:03:54,910 --> 00:03:57,140
And as you can see, these grid lines
72
00:03:57,140 --> 00:04:01,430
are numbered from one to the number of columns plus one,
73
00:04:01,430 --> 00:04:04,170
and the number of rows plus one.
74
00:04:04,170 --> 00:04:06,460
So if we have three columns,
75
00:04:06,460 --> 00:04:09,540
then we have four grid lines for the columns.
76
00:04:09,540 --> 00:04:11,290
And if we have two rows,
77
00:04:11,290 --> 00:04:14,640
then we have three grid lines for the rows.
78
00:04:14,640 --> 00:04:16,940
And these numbers are actually important
79
00:04:16,940 --> 00:04:20,080
because we can use them to place a grid item
80
00:04:20,080 --> 00:04:22,870
exactly in one place in the grid
81
00:04:22,870 --> 00:04:24,780
where we want it to be.
82
00:04:24,780 --> 00:04:28,090
Now the intersection of all these grid lines,
83
00:04:28,090 --> 00:04:31,470
so both the grid lines for the columns and the rows
84
00:04:31,470 --> 00:04:33,560
then creates all these areas
85
00:04:33,560 --> 00:04:36,730
into which we can place or grid items.
86
00:04:36,730 --> 00:04:41,730
And these areas are called the grid cells, okay?
87
00:04:42,020 --> 00:04:44,480
So grid cells are always created,
88
00:04:44,480 --> 00:04:47,350
but they don't always need to be filled.
89
00:04:47,350 --> 00:04:50,850
So in this case we only have five grid items,
90
00:04:50,850 --> 00:04:53,290
but there are still six cells
91
00:04:53,290 --> 00:04:55,210
simply because this is a grid
92
00:04:55,210 --> 00:04:57,890
with three columns and two rows,
93
00:04:57,890 --> 00:05:00,910
and so three times two makes six.
94
00:05:00,910 --> 00:05:05,170
So again, each of these spaces is called a grid cell,
95
00:05:05,170 --> 00:05:08,770
but they don't always need to be filled by a grid item
96
00:05:08,770 --> 00:05:12,940
and also they don't need to be filled entirely.
97
00:05:12,940 --> 00:05:16,030
Next up, as we saw in the last lecture,
98
00:05:16,030 --> 00:05:19,690
we can actually create spaces between the grid items
99
00:05:19,690 --> 00:05:23,580
and these are then called gutters or gaps.
100
00:05:23,580 --> 00:05:27,260
So remember for that we use the gap property
101
00:05:27,260 --> 00:05:31,070
or also the row gap and column gap property.
102
00:05:31,070 --> 00:05:34,893
So technically these are actually called gutters, okay?
103
00:05:35,860 --> 00:05:38,660
Finally, another term that is commonly used
104
00:05:38,660 --> 00:05:43,660
when we talk about CSS Grid is the term of grid track.
105
00:05:43,660 --> 00:05:48,260
So a grid track can be a row or also a column.
106
00:05:48,260 --> 00:05:51,050
So each of these are grid tracks
107
00:05:51,050 --> 00:05:53,140
and so in this example here
108
00:05:53,140 --> 00:05:57,863
we have two row tracks and three column tracks, okay?
109
00:05:59,210 --> 00:06:02,320
And we call these tracks because these concepts
110
00:06:02,320 --> 00:06:05,160
are a bit more about the space itself
111
00:06:05,160 --> 00:06:07,780
and not about the grid items.
112
00:06:07,780 --> 00:06:11,620
So a little bit like a grid cell right?
113
00:06:11,620 --> 00:06:14,370
So remember a grid cell might be filled
114
00:06:14,370 --> 00:06:16,440
by a grid item or not,
115
00:06:16,440 --> 00:06:20,550
but what matters is that there is some theoretical space
116
00:06:20,550 --> 00:06:23,330
and the same applies to the grid track.
117
00:06:23,330 --> 00:06:27,720
Okay, but now I promise, that's it about terminology.
118
00:06:27,720 --> 00:06:30,990
And I know that this is a lot to take in,
119
00:06:30,990 --> 00:06:32,850
so please don't worry too much
120
00:06:32,850 --> 00:06:36,000
about all these terms at this point.
121
00:06:36,000 --> 00:06:38,930
So with time this will come naturally to you,
122
00:06:38,930 --> 00:06:41,720
specially things like grid cell,
123
00:06:41,720 --> 00:06:45,470
the grid lines and the gutters or gaps.
124
00:06:45,470 --> 00:06:47,020
So these are important terms
125
00:06:47,020 --> 00:06:48,770
that we're gonna use all the time
126
00:06:48,770 --> 00:06:52,760
and so at some point you will naturally know about this.
127
00:06:53,930 --> 00:06:57,850
And now to finish just like in the flexbox lecture,
128
00:06:57,850 --> 00:07:00,410
let's now take a look at an overview
129
00:07:00,410 --> 00:07:02,100
of some of the properties
130
00:07:02,100 --> 00:07:07,020
that we can use on the grid container and on the grid item.
131
00:07:07,020 --> 00:07:10,400
And starting with the properties for the grid container
132
00:07:10,400 --> 00:07:14,450
the most important ones are the grid template rows,
133
00:07:14,450 --> 00:07:19,160
grid template columns, the column gap, and row gap,
134
00:07:19,160 --> 00:07:21,980
which together make up the gap property.
135
00:07:21,980 --> 00:07:25,590
That then also justify items and align items,
136
00:07:25,590 --> 00:07:27,780
which we can use to align the items
137
00:07:27,780 --> 00:07:31,010
inside rows or inside columns.
138
00:07:31,010 --> 00:07:34,373
So in other words, horizontally and vertically.
139
00:07:35,270 --> 00:07:37,940
So just like before I have the default value
140
00:07:37,940 --> 00:07:41,660
for each of the properties and a short description.
141
00:07:41,660 --> 00:07:44,200
So I think it would be very helpful for you
142
00:07:44,200 --> 00:07:46,800
if you could print out this overview
143
00:07:46,800 --> 00:07:49,990
kind of as a sheet sheet, so you can have attendee
144
00:07:49,990 --> 00:07:53,750
whenever you start writing your own CSS Grid code.
145
00:07:53,750 --> 00:07:57,300
So I will not go over all of these here now one-by-one,
146
00:07:57,300 --> 00:07:59,863
because of course we will do that in practice.
147
00:08:00,730 --> 00:08:04,500
But anyway, there are also two less important properties
148
00:08:04,500 --> 00:08:06,130
on the grid container,
149
00:08:06,130 --> 00:08:09,970
which are justify content and align content.
150
00:08:09,970 --> 00:08:12,350
So these only apply if the container
151
00:08:12,350 --> 00:08:14,500
is actually larger than the grid,
152
00:08:14,500 --> 00:08:17,400
and so these are usually not that important.
153
00:08:17,400 --> 00:08:20,230
And by the way, actually this overview
154
00:08:20,230 --> 00:08:24,720
of the CSS Grid properties does not contain all of them.
155
00:08:24,720 --> 00:08:28,870
So, there is actually a huge amount of CSS Grid properties,
156
00:08:28,870 --> 00:08:32,330
but we will not talk about all of them here in this course,
157
00:08:32,330 --> 00:08:36,410
because that would just be too confusing for beginners.
158
00:08:36,410 --> 00:08:40,540
This course should be comfortable for you as a CSS beginner
159
00:08:40,540 --> 00:08:42,140
and therefore we are not gonna
160
00:08:42,140 --> 00:08:46,710
over-complicate things too much, all right?
161
00:08:46,710 --> 00:08:50,380
So anyway, now about the grid items,
162
00:08:50,380 --> 00:08:54,610
there is the grid column and the grid row properties,
163
00:08:54,610 --> 00:08:57,350
which are very important to place grid items
164
00:08:57,350 --> 00:08:59,850
into a specific cell.
165
00:08:59,850 --> 00:09:04,050
Then finally we have justify-self and align-self,
166
00:09:04,050 --> 00:09:08,110
which hopefully you can recognize from flexbox.
167
00:09:08,110 --> 00:09:11,900
So align-self is used to override align items
168
00:09:11,900 --> 00:09:16,890
and justify-self is used to override justify items
169
00:09:16,890 --> 00:09:19,550
for one individual grid cell,
170
00:09:19,550 --> 00:09:22,690
so again, just like in flexbox.
171
00:09:22,690 --> 00:09:25,890
So this is an overview of the most important
172
00:09:25,890 --> 00:09:29,960
CSS Grid properties that we're gonna use in this course.
173
00:09:29,960 --> 00:09:32,010
So make sure to print this out
174
00:09:32,010 --> 00:09:34,090
and have it next to your keyboard
175
00:09:34,090 --> 00:09:37,093
once we start writing code in the next lecture.
13365
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.