Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,040 --> 00:00:04,973
So now let's style the table that we have been working on.
2
00:00:06,330 --> 00:00:08,360
And as always, let's start
3
00:00:08,360 --> 00:00:11,280
by giving our component a fixed width,
4
00:00:11,280 --> 00:00:13,453
and also center it in the Viewport.
5
00:00:15,890 --> 00:00:18,280
So here, I'm gonna to select the table,
6
00:00:18,280 --> 00:00:22,233
simply using the element selector of the table.
7
00:00:24,500 --> 00:00:28,170
So, a width again of 800 pixels,
8
00:00:28,170 --> 00:00:29,810
and just so we can see this,
9
00:00:29,810 --> 00:00:32,393
let's actually also give it some background color,
10
00:00:35,780 --> 00:00:38,970
just for a short amount of time.
11
00:00:38,970 --> 00:00:40,210
Alright?
12
00:00:40,210 --> 00:00:43,580
So you see that now the table got wider
13
00:00:43,580 --> 00:00:45,740
and then these three columns here,
14
00:00:45,740 --> 00:00:49,840
basically grew in order to fill that empty space.
15
00:00:49,840 --> 00:00:52,300
And we can also see that by default,
16
00:00:52,300 --> 00:00:55,100
now this text here is centered.
17
00:00:55,100 --> 00:00:58,390
So that's because this is a <th> element.
18
00:00:58,390 --> 00:01:01,140
So a table had cell, because the same,
19
00:01:01,140 --> 00:01:03,990
we can see here in these four.
20
00:01:03,990 --> 00:01:07,500
So this one are now also centered, right?
21
00:01:07,500 --> 00:01:08,750
But this column here,
22
00:01:08,750 --> 00:01:11,720
did not expand like these three did,
23
00:01:11,720 --> 00:01:14,260
and that's simply because all of these cells here
24
00:01:14,260 --> 00:01:15,743
our table had cells.
25
00:01:17,810 --> 00:01:18,930
Alright?
26
00:01:18,930 --> 00:01:22,120
So now let's center this inside of the Viewport,
27
00:01:22,120 --> 00:01:24,173
but let's actually use another way.
28
00:01:25,010 --> 00:01:28,283
So we have been doing always, this trick,
29
00:01:29,160 --> 00:01:32,280
so margin, something and then auto.
30
00:01:32,280 --> 00:01:35,450
And of course that is going to work here as well.
31
00:01:35,450 --> 00:01:37,312
However, I want to start showing you
32
00:01:37,312 --> 00:01:42,312
that there are always multiple ways of doing things in CSS.
33
00:01:42,410 --> 00:01:44,850
So, can you think of another way
34
00:01:44,850 --> 00:01:46,780
of centering our entire page
35
00:01:46,780 --> 00:01:49,850
here inside of the Viewport?
36
00:01:49,850 --> 00:01:52,690
And remember that this Viewport that we see here,
37
00:01:52,690 --> 00:01:54,720
is basically the body.
38
00:01:54,720 --> 00:01:56,990
So how could we do this?
39
00:01:56,990 --> 00:01:59,770
Well, one way of doing it
40
00:01:59,770 --> 00:02:03,203
is to say that the body should be a flex container.
41
00:02:04,400 --> 00:02:09,290
So display, flex, and there is nothing wrong with that.
42
00:02:09,290 --> 00:02:12,460
So the body is just like any other element,
43
00:02:12,460 --> 00:02:15,170
so we can also make it a flex container,
44
00:02:15,170 --> 00:02:17,920
just like any of the other elements.
45
00:02:17,920 --> 00:02:21,810
And so now in order to then center all the flex items,
46
00:02:21,810 --> 00:02:24,700
which in this case, is just one,
47
00:02:24,700 --> 00:02:29,370
remember that we use justify content, set to center.
48
00:02:29,370 --> 00:02:30,573
And there we go.
49
00:02:32,120 --> 00:02:35,453
Now let's just give this here some margin to the top still.
50
00:02:41,250 --> 00:02:42,560
Alright.
51
00:02:42,560 --> 00:02:45,830
Now let's remove this color here.
52
00:02:45,830 --> 00:02:48,110
And now I actually want to give this table
53
00:02:48,110 --> 00:02:49,853
for now, some borders.
54
00:02:52,630 --> 00:02:57,630
So we can say border, one pixel and then solid as always.
55
00:02:57,770 --> 00:03:00,170
And let's just use some gray,
56
00:03:00,170 --> 00:03:02,183
well we can go with this one, actually.
57
00:03:03,060 --> 00:03:04,710
And so this will add, basically,
58
00:03:04,710 --> 00:03:07,223
a border all around the table.
59
00:03:08,140 --> 00:03:10,680
And now let's say we wanted to add borders
60
00:03:10,680 --> 00:03:13,000
inside of the whole table.
61
00:03:13,000 --> 00:03:15,120
So between all the cells,
62
00:03:15,120 --> 00:03:17,370
like in a more traditional table.
63
00:03:17,370 --> 00:03:20,623
So between all the rows and all the columns.
64
00:03:22,090 --> 00:03:23,100
So to do that,
65
00:03:23,100 --> 00:03:26,030
we can simply select all of the tables cells
66
00:03:26,030 --> 00:03:28,683
and then add a border around all of them.
67
00:03:30,980 --> 00:03:34,720
Now, our cells are these <td> elements
68
00:03:34,720 --> 00:03:38,173
and also the <th> elements, right?
69
00:03:39,050 --> 00:03:42,270
So we need to select both of them at the same time here,
70
00:03:42,270 --> 00:03:44,323
if we want to style them in the same way.
71
00:03:45,760 --> 00:03:47,710
And for now, that's what we want to do.
72
00:03:50,660 --> 00:03:52,580
And so, as I was saying,
73
00:03:52,580 --> 00:03:55,810
let's add some border here,
74
00:03:55,810 --> 00:03:58,680
of one pixel, solid
75
00:04:00,150 --> 00:04:01,393
and our gray color,
76
00:04:03,450 --> 00:04:04,773
and there we go.
77
00:04:05,730 --> 00:04:08,120
And that looks a little bit strange,
78
00:04:08,120 --> 00:04:11,730
but if we think about it, this result actually makes sense.
79
00:04:11,730 --> 00:04:15,160
So each of the cells has a border around it.
80
00:04:15,160 --> 00:04:18,310
And so that's why here, basically, we have two borders,
81
00:04:18,310 --> 00:04:19,733
very close to each other.
82
00:04:21,100 --> 00:04:22,230
Right?
83
00:04:22,230 --> 00:04:26,040
Now, usually we don't want this to look in this way,
84
00:04:26,040 --> 00:04:28,633
and so there is this weird property
85
00:04:28,633 --> 00:04:31,313
which is called border-collapse.
86
00:04:32,830 --> 00:04:35,120
And so basically, what we will do here
87
00:04:35,120 --> 00:04:38,610
is that when we have two borders close to one another,
88
00:04:38,610 --> 00:04:42,010
like we have here, we can make them collapse.
89
00:04:42,010 --> 00:04:46,080
So collapse means that these will basically be put together
90
00:04:46,080 --> 00:04:47,623
into just one border.
91
00:04:49,040 --> 00:04:51,320
So just like this.
92
00:04:51,320 --> 00:04:53,060
So, see the difference?
93
00:04:53,060 --> 00:04:55,230
Before, we basically had two borders
94
00:04:55,230 --> 00:04:56,640
in the same position.
95
00:04:56,640 --> 00:04:58,160
So here, for example,
96
00:04:58,160 --> 00:05:00,410
coming from the top of this one
97
00:05:00,410 --> 00:05:03,030
and coming from the bottom of this one.
98
00:05:03,030 --> 00:05:05,840
And so, if we say we want to collapse them,
99
00:05:05,840 --> 00:05:08,173
then they are transformed into just one.
100
00:05:09,430 --> 00:05:11,633
Now here, let's also add some padding.
101
00:05:16,130 --> 00:05:20,780
So 16 top and bottom, 24 left and right,
102
00:05:20,780 --> 00:05:21,613
let's say.
103
00:05:23,160 --> 00:05:26,580
So that is starting to look more like a real table.
104
00:05:26,580 --> 00:05:29,470
And actually, we want all of the text here
105
00:05:29,470 --> 00:05:32,090
to be aligned to the left.
106
00:05:32,090 --> 00:05:33,710
So no centering.
107
00:05:33,710 --> 00:05:34,743
And so text,
108
00:05:35,710 --> 00:05:36,543
align,
109
00:05:37,750 --> 00:05:38,583
left.
110
00:05:40,230 --> 00:05:41,063
Nice.
111
00:05:41,063 --> 00:05:42,940
So that is starting to look a little bit
112
00:05:42,940 --> 00:05:44,663
like what we have here,
113
00:05:48,140 --> 00:05:49,610
right?
114
00:05:49,610 --> 00:05:53,950
But now let's actually get rid of these borders
115
00:05:53,950 --> 00:05:56,300
because in this case we don't want it,
116
00:05:56,300 --> 00:05:59,400
but I still wanted show you how you could add borders
117
00:05:59,400 --> 00:06:00,800
in the correct way,
118
00:06:00,800 --> 00:06:04,910
if you wanted to do that for your own tables at some point.
119
00:06:04,910 --> 00:06:05,743
Great.
120
00:06:06,680 --> 00:06:08,870
Now, remember what we want to do now
121
00:06:08,870 --> 00:06:11,330
is to format this first row here
122
00:06:11,330 --> 00:06:14,260
to have this green background color,
123
00:06:14,260 --> 00:06:16,153
and the text should also be white.
124
00:06:17,430 --> 00:06:18,263
Okay.
125
00:06:19,470 --> 00:06:21,883
So, how are we going to do that?
126
00:06:23,260 --> 00:06:25,700
Well, we somehow need to select
127
00:06:25,700 --> 00:06:29,650
basically, all of these cells that we have here
128
00:06:29,650 --> 00:06:31,750
and format them individually.
129
00:06:31,750 --> 00:06:36,620
So we usually never format like an entire row or the head.
130
00:06:36,620 --> 00:06:40,763
So, instead, what we do is to format the cells themselves.
131
00:06:42,450 --> 00:06:45,493
Now these four here are <th> elements,
132
00:06:46,610 --> 00:06:48,750
but we cannot just do this
133
00:06:48,750 --> 00:06:51,963
because they're also <th> elements right here,
134
00:06:53,330 --> 00:06:56,120
so inside of the table body.
135
00:06:56,120 --> 00:06:59,530
But we just want the ones that are in the table head.
136
00:06:59,530 --> 00:07:03,610
And so we can simply do this, right?
137
00:07:03,610 --> 00:07:05,200
So a descendant selector,
138
00:07:05,200 --> 00:07:08,030
selecting only the table head cells
139
00:07:08,030 --> 00:07:11,490
that are inside of the actual table head.
140
00:07:11,490 --> 00:07:13,620
And so here, we can now give them
141
00:07:13,620 --> 00:07:15,480
that green background color
142
00:07:20,250 --> 00:07:23,333
and also set the text to white.
143
00:07:28,100 --> 00:07:29,100
Okay.
144
00:07:29,100 --> 00:07:32,630
So that is starting to look better and better.
145
00:07:32,630 --> 00:07:33,740
Now we have this issue
146
00:07:33,740 --> 00:07:37,410
that we have, a kind of these invisible borders here,
147
00:07:37,410 --> 00:07:39,500
basically between these cells.
148
00:07:39,500 --> 00:07:41,070
And in order to fix that,
149
00:07:41,070 --> 00:07:43,480
we actually need to make them disappear
150
00:07:43,480 --> 00:07:46,293
by turning this one here back on.
151
00:07:47,250 --> 00:07:50,860
So we do in fact, always need this border collapse here,
152
00:07:50,860 --> 00:07:52,950
set to collapse.
153
00:07:52,950 --> 00:07:54,000
Alright.
154
00:07:54,000 --> 00:07:56,680
And so now, since we didn't specify any borders
155
00:07:56,680 --> 00:07:59,790
than these invisible borders that we had here before
156
00:07:59,790 --> 00:08:00,873
kind of disappeared.
157
00:08:02,270 --> 00:08:04,850
Now, if we take a look here at the demo,
158
00:08:04,850 --> 00:08:07,010
we see that actually the four columns
159
00:08:07,010 --> 00:08:08,683
have the exact same width.
160
00:08:09,670 --> 00:08:13,200
So, let me show you how we can also do that.
161
00:08:13,200 --> 00:08:15,810
And so basically what we need to do is
162
00:08:15,810 --> 00:08:20,160
to format the width of these very first cells.
163
00:08:20,160 --> 00:08:22,050
So the ones that are in the head
164
00:08:22,050 --> 00:08:24,780
and then the entire table will follow.
165
00:08:24,780 --> 00:08:27,560
So it will automatically adjust itself.
166
00:08:27,560 --> 00:08:31,870
If we say that the width of each of these table had cells,
167
00:08:31,870 --> 00:08:35,563
so these four here should be 25%.
168
00:08:36,680 --> 00:08:38,850
So 25% is of course,
169
00:08:38,850 --> 00:08:43,850
a hundred percent divided by four and there we go.
170
00:08:44,460 --> 00:08:45,490
Alright?
171
00:08:45,490 --> 00:08:47,543
And with that, we are almost done.
172
00:08:48,670 --> 00:08:50,030
So if we compare it here,
173
00:08:50,030 --> 00:08:52,230
it looks almost the same
174
00:08:52,230 --> 00:08:54,860
well the text is a little bit bigger,
175
00:08:54,860 --> 00:08:57,170
let's fix that as well.
176
00:08:57,170 --> 00:09:02,170
So here, we can say that the font size should be 18 pixels.
177
00:09:03,660 --> 00:09:04,670
Alright?
178
00:09:04,670 --> 00:09:08,550
But now what's missing is this very typical table formatting
179
00:09:08,550 --> 00:09:12,433
of adding these zebra stripes, which is what we call them.
180
00:09:14,670 --> 00:09:16,190
So basically that's having
181
00:09:16,190 --> 00:09:18,030
this alternating background colors,
182
00:09:18,030 --> 00:09:23,030
which makes the table really easy to read and to scan.
183
00:09:23,140 --> 00:09:25,239
Now, I noticed that we're kind of
184
00:09:25,239 --> 00:09:27,830
missing one of the rows here.
185
00:09:27,830 --> 00:09:30,450
So we have the width, depth and weight,
186
00:09:30,450 --> 00:09:32,640
but there's no height.
187
00:09:32,640 --> 00:09:35,730
So this second row here is missing somehow.
188
00:09:35,730 --> 00:09:36,980
So let's quickly add that.
189
00:09:36,980 --> 00:09:39,980
And I will just copy all of this here
190
00:09:41,660 --> 00:09:44,170
and paste it down here.
191
00:09:44,170 --> 00:09:45,540
And so here, this is height
192
00:09:49,070 --> 00:09:53,103
and a hundred, 110 and 90.
193
00:09:56,190 --> 00:09:57,240
Alright.
194
00:09:57,240 --> 00:10:00,240
And so this now actually looks exactly the same
195
00:10:00,240 --> 00:10:02,283
except for the zebra stripes.
196
00:10:03,400 --> 00:10:06,720
So, let's do those zebra stripes.
197
00:10:06,720 --> 00:10:09,520
And so let me show you how we can do that.
198
00:10:09,520 --> 00:10:11,670
So inside of the tbody,
199
00:10:11,670 --> 00:10:14,810
we now basically want to select the odd rows
200
00:10:14,810 --> 00:10:16,560
and the even ones.
201
00:10:16,560 --> 00:10:17,830
So with odd, I mean,
202
00:10:17,830 --> 00:10:22,830
the row number one, three, five and so on and so forth.
203
00:10:23,000 --> 00:10:25,010
And with odd, we want the second one,
204
00:10:25,010 --> 00:10:29,650
the fourth, sixth, eighth, and so on.
205
00:10:29,650 --> 00:10:34,650
And so let's select the tr's inside of the tbody,
206
00:10:35,530 --> 00:10:37,200
so the table rows.
207
00:10:37,200 --> 00:10:39,000
And then, remember that we have
208
00:10:39,000 --> 00:10:42,253
this very handy nth child pseudo class.
209
00:10:43,600 --> 00:10:47,510
So nth child, which, remember,
210
00:10:47,510 --> 00:10:50,990
basically allowed us to select any of the child elements
211
00:10:50,990 --> 00:10:53,250
by their order number.
212
00:10:53,250 --> 00:10:55,600
So for example, we could do this,
213
00:10:55,600 --> 00:10:57,570
select just the third one
214
00:10:59,050 --> 00:11:02,770
and set the background color to red there.
215
00:11:02,770 --> 00:11:06,850
And so now the entire third row here would become red.
216
00:11:06,850 --> 00:11:09,418
Now, I said previously here that we actually,
217
00:11:09,418 --> 00:11:12,800
usually select the cells individually,
218
00:11:12,800 --> 00:11:16,010
but back here, that was basically
219
00:11:16,010 --> 00:11:19,120
because I also needed to individually style
220
00:11:19,120 --> 00:11:22,180
actually, these cells with this width,
221
00:11:22,180 --> 00:11:25,583
but we could in fact also have done this.
222
00:11:26,910 --> 00:11:29,910
So thead and then the tr,
223
00:11:29,910 --> 00:11:31,933
and here, of course there's only one.
224
00:11:35,430 --> 00:11:39,640
And so, the result would look exactly the same, right?
225
00:11:39,640 --> 00:11:43,370
But this styling here of the width of the individual cells,
226
00:11:43,370 --> 00:11:47,360
will of course, need to stay in this selector right here,
227
00:11:47,360 --> 00:11:48,283
so in this rule.
228
00:11:49,320 --> 00:11:50,840
Alright.
229
00:11:50,840 --> 00:11:55,310
So again, many times we do format only individual cells,
230
00:11:55,310 --> 00:11:58,450
but in this case where we want to select the row,
231
00:11:58,450 --> 00:12:03,450
based on the order, we actually need to style rows.
232
00:12:03,610 --> 00:12:04,970
Alright.
233
00:12:04,970 --> 00:12:07,450
And so, I think I explained this before,
234
00:12:07,450 --> 00:12:11,327
that here we can use a keyword of "odd" and "even".
235
00:12:13,040 --> 00:12:16,740
And so, the odd ones are now a red.
236
00:12:16,740 --> 00:12:20,970
So again, that's one, three, five and so on.
237
00:12:20,970 --> 00:12:25,923
And then, let's do the same with even.
238
00:12:28,070 --> 00:12:31,400
And so here, some other color,
239
00:12:31,400 --> 00:12:34,300
and of course, that looks very bad.
240
00:12:34,300 --> 00:12:37,250
And so let's get some actual colors again here
241
00:12:37,250 --> 00:12:39,180
from open color.
242
00:12:39,180 --> 00:12:40,970
And so let's actually use this
243
00:12:40,970 --> 00:12:44,713
very, very light gray here for the odd ones,
244
00:12:46,700 --> 00:12:48,980
and then some darker tone,
245
00:12:48,980 --> 00:12:52,403
maybe this one here for the even cells,
246
00:12:54,450 --> 00:12:56,203
or the even rows, actually.
247
00:12:57,110 --> 00:13:00,600
And yeah, there we go.
248
00:13:00,600 --> 00:13:01,620
That's it.
249
00:13:01,620 --> 00:13:03,390
Let's compare it.
250
00:13:03,390 --> 00:13:05,453
And it is exactly the same one.
251
00:13:06,460 --> 00:13:07,350
Great.
252
00:13:07,350 --> 00:13:10,580
And so, this is the basics of creating
253
00:13:10,580 --> 00:13:14,073
and of styling tables with HTML and CSS.
17735
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.