Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,470 --> 00:00:03,070
Welcome back.
2
00:00:03,070 --> 00:00:04,010
In this lecture,
3
00:00:04,010 --> 00:00:08,300
we will learn how to work with colors in CSS.
4
00:00:08,300 --> 00:00:12,550
However, before we can actually go back to our CSS,
5
00:00:12,550 --> 00:00:15,750
we first need to learn a little bit about the theory
6
00:00:15,750 --> 00:00:18,673
of how to represent colors using code.
7
00:00:20,970 --> 00:00:24,020
Now, there are many ways of representing colors
8
00:00:24,020 --> 00:00:28,100
in computers and basically in writing code,
9
00:00:28,100 --> 00:00:32,830
but one of the more traditional models is the RGB model.
10
00:00:32,830 --> 00:00:34,790
So in the RGB model,
11
00:00:34,790 --> 00:00:37,510
every single color can be represented
12
00:00:37,510 --> 00:00:42,510
by any combination of red, green, and blue colors.
13
00:00:43,030 --> 00:00:45,950
So that looks something like this.
14
00:00:45,950 --> 00:00:49,060
And maybe you have already seen a diagram like this
15
00:00:49,060 --> 00:00:51,793
somewhere in school or something like that.
16
00:00:52,630 --> 00:00:57,630
So anyway, in order to actually represent a certain color,
17
00:00:57,830 --> 00:01:00,900
we need to give each of the three base colors,
18
00:01:00,900 --> 00:01:05,160
any value between zero and 255.
19
00:01:05,160 --> 00:01:06,540
And so with that,
20
00:01:06,540 --> 00:01:11,540
we can define a total of 16.8 million different colors.
21
00:01:12,220 --> 00:01:16,460
So let's understand this a little bit using our diagram here
22
00:01:16,460 --> 00:01:19,350
and starting with the pure red color.
23
00:01:19,350 --> 00:01:24,220
Of course, in this channel, red is at the complete maximum,
24
00:01:24,220 --> 00:01:28,320
which is 255 and the other two channels.
25
00:01:28,320 --> 00:01:31,970
So the other two base colors are at zero.
26
00:01:31,970 --> 00:01:36,710
So there is no green whatsoever and no blue whatsoever.
27
00:01:36,710 --> 00:01:39,510
And so this is why this is pure red.
28
00:01:39,510 --> 00:01:40,390
So again,
29
00:01:40,390 --> 00:01:42,930
the red channel is at the maximum value
30
00:01:42,930 --> 00:01:45,600
and all the other ones are at zero.
31
00:01:45,600 --> 00:01:49,260
And the same of course, for blue and for green.
32
00:01:49,260 --> 00:01:54,100
So in blue, the blue channel is at a maximum of 255,
33
00:01:54,100 --> 00:01:57,320
and the other one's at zero and in green,
34
00:01:57,320 --> 00:02:00,290
basically the same happens for green.
35
00:02:00,290 --> 00:02:02,600
Next up we have white.
36
00:02:02,600 --> 00:02:05,520
And in white, we have all the three colors
37
00:02:05,520 --> 00:02:08,830
at the maximum of 255.
38
00:02:08,830 --> 00:02:12,390
So basically having all the colors at maximum
39
00:02:12,390 --> 00:02:15,890
gives us a complete white while at the other end
40
00:02:15,890 --> 00:02:19,700
of the spectrum, when we have all the colors at zero,
41
00:02:19,700 --> 00:02:22,640
we get a complete black color.
42
00:02:22,640 --> 00:02:26,200
Finally, the other three colors that we have here
43
00:02:26,200 --> 00:02:30,330
are a mix of the other two colors that they are made of.
44
00:02:30,330 --> 00:02:34,040
So you'll see that this magenta here is red and blue
45
00:02:34,040 --> 00:02:37,370
at the maximum and no green at all.
46
00:02:37,370 --> 00:02:42,370
Then we have this I think is called cyan or cyan color,
47
00:02:42,410 --> 00:02:47,400
which has a red at zero and GNB at its maximum.
48
00:02:47,400 --> 00:02:50,452
And finally yellow has blue at zero
49
00:02:50,452 --> 00:02:53,143
and the other two at 255.
50
00:02:54,020 --> 00:02:54,880
Great.
51
00:02:54,880 --> 00:02:57,710
So I hope that this makes sense.
52
00:02:57,710 --> 00:03:00,620
And now that we have a basic understanding
53
00:03:00,620 --> 00:03:03,040
of how the RGB model works,
54
00:03:03,040 --> 00:03:06,160
let's actually see how we can represent
55
00:03:06,160 --> 00:03:09,513
or how we can define colors in CSS.
56
00:03:10,530 --> 00:03:14,380
So in CSS, we have two ways of writing colors
57
00:03:14,380 --> 00:03:16,300
using the RGB model.
58
00:03:16,300 --> 00:03:21,300
And those are the RGB notation and hexadecimal notation.
59
00:03:21,410 --> 00:03:24,220
So by using the RGB notation,
60
00:03:24,220 --> 00:03:28,490
all we do is to use this RGB function in CSS,
61
00:03:28,490 --> 00:03:31,760
and then we simply specify the values for each
62
00:03:31,760 --> 00:03:35,660
of the three color channels, red, green, and blue.
63
00:03:35,660 --> 00:03:37,060
So for example,
64
00:03:37,060 --> 00:03:40,540
if we set green and blue to the maximum values,
65
00:03:40,540 --> 00:03:44,680
then we get this cyan color just as we saw
66
00:03:44,680 --> 00:03:46,570
in the last slide.
67
00:03:46,570 --> 00:03:50,120
Another example, which is a lot more real world,
68
00:03:50,120 --> 00:03:52,920
is this orange color right here.
69
00:03:52,920 --> 00:03:55,080
So here are the numbers for each channel
70
00:03:55,080 --> 00:03:57,470
look a little bit more random.
71
00:03:57,470 --> 00:04:00,810
And so this is how we get a real looking color
72
00:04:00,810 --> 00:04:04,810
using CSS and using the RGB notation.
73
00:04:04,810 --> 00:04:07,960
Then besides the normal RGB function,
74
00:04:07,960 --> 00:04:11,820
there is also RGB with transparency.
75
00:04:11,820 --> 00:04:14,890
And transparency is also called alpha.
76
00:04:14,890 --> 00:04:18,660
And so that's why this function is called RGBA.
77
00:04:18,660 --> 00:04:22,050
So here we can specify a fourth value,
78
00:04:22,050 --> 00:04:24,213
which in this case is the 0.3,
79
00:04:25,050 --> 00:04:28,350
and this will then give this color a transparency
80
00:04:28,350 --> 00:04:29,513
as we can see here.
81
00:04:30,750 --> 00:04:34,930
Looking at this other example, if we, for example define
82
00:04:34,930 --> 00:04:36,423
an alpha value of 0.7,
83
00:04:37,480 --> 00:04:40,930
then we see that this color is actually transparent
84
00:04:40,930 --> 00:04:44,660
as visible when we put it on top of another color
85
00:04:44,660 --> 00:04:47,120
like this green square.
86
00:04:47,120 --> 00:04:50,110
Now, of course we don't have to manually come up
87
00:04:50,110 --> 00:04:52,610
with these numbers for these colors.
88
00:04:52,610 --> 00:04:53,660
Okay.
89
00:04:53,660 --> 00:04:57,443
So we don't have to like manually write 244, 179, 63
90
00:04:59,800 --> 00:05:02,000
in order to get this orange.
91
00:05:02,000 --> 00:05:06,320
So usually we just copy a certain color from somewhere,
92
00:05:06,320 --> 00:05:10,960
or we can also generate it with a color picker in VS code.
93
00:05:10,960 --> 00:05:14,510
And so that will then automatically give us these numbers.
94
00:05:14,510 --> 00:05:17,640
But all this is still very important so that you know
95
00:05:17,640 --> 00:05:20,300
what these numbers actually mean.
96
00:05:20,300 --> 00:05:22,170
Okay. But moving on,
97
00:05:22,170 --> 00:05:25,480
let's now talk about the hexadecimal notation,
98
00:05:25,480 --> 00:05:29,030
which is actually a bit more used in CSS.
99
00:05:29,030 --> 00:05:31,800
So here in the hexadecimal notation,
100
00:05:31,800 --> 00:05:36,250
we don't use a scale from zero to 255,
101
00:05:36,250 --> 00:05:40,759
but instead we use a scale from zero to FF.
102
00:05:40,759 --> 00:05:45,400
And FF is basically the same as 255,
103
00:05:45,400 --> 00:05:48,200
but in a hexadecimal scale.
104
00:05:48,200 --> 00:05:51,900
And we don't need to go into what that actually means,
105
00:05:51,900 --> 00:05:54,080
but basically hexadecimal numbers
106
00:05:54,080 --> 00:05:58,830
do not go from zero to nine, but from zero to 15.
107
00:05:58,830 --> 00:06:02,540
So there are 16 different numbers and not just 10,
108
00:06:02,540 --> 00:06:05,080
and the last one F.
109
00:06:05,080 --> 00:06:10,080
And so that's why FF here means 255.
110
00:06:10,540 --> 00:06:13,270
Now translating that to CSS,
111
00:06:13,270 --> 00:06:16,260
we write hexadecimal notation like this,
112
00:06:16,260 --> 00:06:20,730
with the hash then the value for red, green, and blue,
113
00:06:20,730 --> 00:06:23,200
just as I have it here on this screen.
114
00:06:23,200 --> 00:06:25,280
And so this then gives us, of course
115
00:06:25,280 --> 00:06:29,280
the exact same number as with the RGB notation.
116
00:06:29,280 --> 00:06:30,960
And the same can of course be done
117
00:06:30,960 --> 00:06:35,230
with this orange example color that I have down here.
118
00:06:35,230 --> 00:06:37,927
So we can represent as using F4B33F.
119
00:06:40,110 --> 00:06:43,070
And again, this looks kind of random
120
00:06:43,070 --> 00:06:46,320
and so we usually just copy us from the color picker
121
00:06:46,320 --> 00:06:47,940
in VS code.
122
00:06:47,940 --> 00:06:50,030
Now in hexadecimal notation,
123
00:06:50,030 --> 00:06:52,940
there's also something called the shorthand,
124
00:06:52,940 --> 00:06:57,590
which we can use when all the colors are identical pairs.
125
00:06:57,590 --> 00:07:02,100
So in our cyan color here, we have two zeros, two Fs,
126
00:07:02,100 --> 00:07:03,690
and again, two Fs.
127
00:07:03,690 --> 00:07:07,080
And so we can abbreviate debt into our shorthand
128
00:07:07,080 --> 00:07:07,913
writing 0FF.
129
00:07:09,470 --> 00:07:10,820
All right.
130
00:07:10,820 --> 00:07:14,010
And now a little bit about how we actually do things
131
00:07:14,010 --> 00:07:17,070
in practice in the real world.
132
00:07:17,070 --> 00:07:21,780
So in practice, we mostly use the hexadecimal notation,
133
00:07:21,780 --> 00:07:26,780
and then if we need transparency, we use the RGBA function.
134
00:07:27,190 --> 00:07:30,943
So as you see here on the left side with the alpha value.
135
00:07:31,830 --> 00:07:34,590
Finally, just something about grace,
136
00:07:34,590 --> 00:07:36,730
which are a special kind of color
137
00:07:36,730 --> 00:07:39,490
that we need all the time in CSS.
138
00:07:39,490 --> 00:07:42,250
So basically in the RGB model,
139
00:07:42,250 --> 00:07:44,930
when the three colors in the three channels
140
00:07:44,930 --> 00:07:49,510
are exactly the same, what we get is a gray color.
141
00:07:49,510 --> 00:07:52,780
So at both extremes of the spectrum,
142
00:07:52,780 --> 00:07:56,730
when all of the values are zero, we get complete black,
143
00:07:56,730 --> 00:08:01,730
and when all of them are at maximum, so at 205,
144
00:08:01,790 --> 00:08:05,580
or at FF then we get white.
145
00:08:05,580 --> 00:08:07,940
But of course there are many other gray colors
146
00:08:07,940 --> 00:08:10,480
in between that we can use.
147
00:08:10,480 --> 00:08:11,630
And to be precise,
148
00:08:11,630 --> 00:08:16,630
there are exactly 256 pure grays to choose from.
149
00:08:17,090 --> 00:08:20,600
And one of them is this one, for example.
150
00:08:20,600 --> 00:08:25,150
So where red, green, and blue are all at 69.
151
00:08:25,150 --> 00:08:28,180
So this gives us this nice gray color,
152
00:08:28,180 --> 00:08:33,140
which has the hexadecimal code of 444444
153
00:08:33,140 --> 00:08:38,140
which in the shorthand notation can be written as just 444.
154
00:08:38,730 --> 00:08:42,330
So this one, I like to use a lot for text color.
155
00:08:42,330 --> 00:08:45,240
And of course, let's take a look at another example.
156
00:08:45,240 --> 00:08:49,120
And this one that has all the values at 183,
157
00:08:49,120 --> 00:08:53,350
and it can be represented as B7B7B7.
158
00:08:53,350 --> 00:08:55,810
So in the hexadecimal notation
159
00:08:55,810 --> 00:08:59,310
you will see once again that the three pairs here
160
00:08:59,310 --> 00:09:01,000
are exactly the same.
161
00:09:01,000 --> 00:09:04,260
And so this is the signal dead we have in fact,
162
00:09:04,260 --> 00:09:05,323
a gray color.
163
00:09:06,211 --> 00:09:07,044
Okay.
164
00:09:07,044 --> 00:09:10,050
So now that we know a little bit about the theory of color
165
00:09:10,050 --> 00:09:13,940
in code and in CSS code in particular,
166
00:09:13,940 --> 00:09:17,280
let's now quickly learn a couple of CSS properties
167
00:09:17,280 --> 00:09:20,323
where we can actually use colors in practice.
168
00:09:21,810 --> 00:09:26,360
And the most simple CSS property that requires a color value
169
00:09:26,360 --> 00:09:28,560
is simply the color property,
170
00:09:28,560 --> 00:09:30,993
which we actually already used before.
171
00:09:31,940 --> 00:09:36,170
So let's say that we want this H1 here to have
172
00:09:36,170 --> 00:09:37,203
a different color.
173
00:09:39,000 --> 00:09:41,980
So let's say color,
174
00:09:41,980 --> 00:09:46,220
and then I will just specify some blue color here.
175
00:09:46,220 --> 00:09:48,943
1098 and ad.
176
00:09:50,580 --> 00:09:53,173
And so this gives us this nice blue color.
177
00:09:54,320 --> 00:09:55,810
So as we just learned,
178
00:09:55,810 --> 00:10:00,570
we have 10 or one zero in the red channel,
179
00:10:00,570 --> 00:10:05,570
98 in the green channel and ad in the blue channel.
180
00:10:06,970 --> 00:10:08,520
Now, as I mentioned before,
181
00:10:08,520 --> 00:10:11,660
we usually use a the VS code color picker.
182
00:10:11,660 --> 00:10:14,897
So we get that by simply hovering over a color,
183
00:10:14,897 --> 00:10:18,173
and then from here, we can choose like any color
184
00:10:18,173 --> 00:10:19,263
that we want.
185
00:10:20,400 --> 00:10:21,870
Right?
186
00:10:21,870 --> 00:10:24,853
So we can change the color here to something else.
187
00:10:25,800 --> 00:10:27,950
So this shade of gray, and then in there,
188
00:10:27,950 --> 00:10:31,843
we can basically define how dark that gray should be.
189
00:10:33,070 --> 00:10:35,150
Also if we click here at the top,
190
00:10:35,150 --> 00:10:38,423
so in this value here, that will change the notation.
191
00:10:39,340 --> 00:10:41,470
So now we have this HSL,
192
00:10:41,470 --> 00:10:43,740
which we actually didn't talk about,
193
00:10:43,740 --> 00:10:47,180
but then if we click again, we got the RGB.
194
00:10:47,180 --> 00:10:50,400
And so this is exactly the same color as before,
195
00:10:50,400 --> 00:10:52,493
but using the RGB function.
196
00:10:53,400 --> 00:10:54,670
Right?
197
00:10:54,670 --> 00:10:56,120
So let me save it.
198
00:10:56,120 --> 00:10:58,570
And now you'll see that we have this green color.
199
00:11:00,410 --> 00:11:04,340
So if we hover it again, we get back to the color picker.
200
00:11:04,340 --> 00:11:06,680
And now this one here is actually the slider
201
00:11:06,680 --> 00:11:08,700
for the alpha value.
202
00:11:08,700 --> 00:11:10,780
So if we start dragging it down,
203
00:11:10,780 --> 00:11:15,700
then you see that automatically it gets changed to RGBA.
204
00:11:15,700 --> 00:11:16,533
Okay?
205
00:11:16,533 --> 00:11:20,543
And then here we can, as I mentioned define the alpha value.
206
00:11:21,480 --> 00:11:23,840
So it actually already got saved,
207
00:11:23,840 --> 00:11:27,423
and you see that now the color is kind of transparent.
208
00:11:28,430 --> 00:11:29,290
Right?
209
00:11:29,290 --> 00:11:33,370
And if we put it even down close to zero,
210
00:11:33,370 --> 00:11:36,473
then now it's almost completely faded out.
211
00:11:38,720 --> 00:11:40,050
All right.
212
00:11:40,050 --> 00:11:43,020
So this is how we work with the color picker,
213
00:11:43,020 --> 00:11:46,950
but now let's actually go back to the color that we had.
214
00:11:46,950 --> 00:11:47,877
So 1098ad.
215
00:11:51,290 --> 00:11:52,790
All right.
216
00:11:52,790 --> 00:11:55,850
Actually another nice trick that I wanted to show you,
217
00:11:55,850 --> 00:11:59,040
so if you just want the color picker,
218
00:11:59,040 --> 00:12:04,040
you can just specify any color first, for example, white,
219
00:12:04,110 --> 00:12:07,157
by using FFF, and then you just hovered the color
220
00:12:07,157 --> 00:12:09,303
and then you get to the color picker.
221
00:12:11,730 --> 00:12:12,563
All right.
222
00:12:12,563 --> 00:12:15,430
So if you want it, for example, this pink,
223
00:12:15,430 --> 00:12:19,760
you can choose that here, maybe with some alpha
224
00:12:19,760 --> 00:12:21,230
and there you go.
225
00:12:21,230 --> 00:12:24,050
And now it applied this pink color,
226
00:12:24,050 --> 00:12:27,350
because when we have two same definitions,
227
00:12:27,350 --> 00:12:28,950
it will simply use the last one.
228
00:12:29,820 --> 00:12:32,033
But again, more about that a bit later.
229
00:12:33,000 --> 00:12:35,210
So let's get rid of that.
230
00:12:35,210 --> 00:12:39,280
And now we actually also want the h2 and the h3
231
00:12:39,280 --> 00:12:40,853
with the exact same color.
232
00:12:42,030 --> 00:12:43,993
So this one and this one.
233
00:12:44,960 --> 00:12:47,100
So how should we do that?
234
00:12:47,100 --> 00:12:50,770
Should we simply copied this property here
235
00:12:50,770 --> 00:12:54,630
to this declaration and then paste it here and here?
236
00:12:54,630 --> 00:12:57,590
Well, not really, right?
237
00:12:57,590 --> 00:13:00,110
Because then we would have the exact same code
238
00:13:00,110 --> 00:13:01,610
in multiple places.
239
00:13:01,610 --> 00:13:05,000
And that is never a good idea, because imagine that,
240
00:13:05,000 --> 00:13:09,030
then we wanted to change the color, for example to orange.
241
00:13:09,030 --> 00:13:10,870
Then we would have to go through
242
00:13:10,870 --> 00:13:14,900
all the three color definitions and change them there.
243
00:13:14,900 --> 00:13:16,960
So change them one by one.
244
00:13:16,960 --> 00:13:20,070
And of course that's not what we want.
245
00:13:20,070 --> 00:13:24,530
So instead, we can define a list of selectors,
246
00:13:24,530 --> 00:13:26,540
just like we did here.
247
00:13:26,540 --> 00:13:29,600
But now only with the ones that we want
248
00:13:29,600 --> 00:13:31,123
the blue collar to apply to.
249
00:13:32,090 --> 00:13:35,170
So that's h1, h2, h3
250
00:13:36,160 --> 00:13:41,040
and now let's simply grab that and paste it here,
251
00:13:41,040 --> 00:13:44,163
give it a safe and there you go.
252
00:13:45,260 --> 00:13:50,260
So now the h1, h2, and h3 have this blue color.
253
00:13:51,150 --> 00:13:55,550
And now, as you also might've noticed one more time,
254
00:13:55,550 --> 00:14:00,550
we have now yet another selector that is applying to the h1.
255
00:14:00,790 --> 00:14:04,190
So we have this one and this one and this one,
256
00:14:04,190 --> 00:14:07,750
and in fact, all the styles of all of them
257
00:14:07,750 --> 00:14:10,450
are now applying to this element.
258
00:14:10,450 --> 00:14:15,290
Next up, let's also define a color for the rest of the text.
259
00:14:15,290 --> 00:14:19,150
So right now the rest of the text is completely black,
260
00:14:19,150 --> 00:14:22,660
but let's use that gray color that I showed you
261
00:14:22,660 --> 00:14:23,963
in one of the slides.
262
00:14:24,810 --> 00:14:27,170
And actually let's do that here.
263
00:14:27,170 --> 00:14:31,900
So we want this text to apply to everything basically,
264
00:14:31,900 --> 00:14:36,670
even these here and the color will then get overwritten
265
00:14:36,670 --> 00:14:38,260
later.
266
00:14:38,260 --> 00:14:40,210
And again, we will learn about why
267
00:14:40,210 --> 00:14:42,543
and how that works in a separate lecture.
268
00:14:43,970 --> 00:14:45,880
So remember for a gray color,
269
00:14:45,880 --> 00:14:49,100
it needs to have the same values in all three channels.
270
00:14:49,100 --> 00:14:54,100
And so let's say 444444, like this,
271
00:14:54,230 --> 00:14:56,610
and if you'll remember the shorthand,
272
00:14:56,610 --> 00:14:58,890
then we can abbreviate this even more.
273
00:14:58,890 --> 00:15:02,210
Because each of the pairs is the same value
274
00:15:02,210 --> 00:15:04,510
as always just 44,
275
00:15:04,510 --> 00:15:07,333
and so we can make this even shorter just like this.
276
00:15:08,950 --> 00:15:10,270
Give it a safe,
277
00:15:10,270 --> 00:15:15,270
and now indeed, all of this text here is a this gray color,
278
00:15:15,720 --> 00:15:18,110
except for the h1, two and three,
279
00:15:18,110 --> 00:15:20,563
which are overwritten here a little bit later.
280
00:15:21,400 --> 00:15:22,320
Great.
281
00:15:22,320 --> 00:15:25,440
So let's now talk about another CSS property
282
00:15:25,440 --> 00:15:27,920
that can accept a color value,
283
00:15:27,920 --> 00:15:30,720
and that is the background color property.
284
00:15:30,720 --> 00:15:33,010
So let's now give our main page header
285
00:15:33,010 --> 00:15:37,130
a slight gray background color to distinguish it a bit
286
00:15:37,130 --> 00:15:39,023
from the rest of the content.
287
00:15:40,450 --> 00:15:42,830
So how could we do that?
288
00:15:42,830 --> 00:15:45,140
Let's come all the way down here.
289
00:15:45,140 --> 00:15:47,160
And the first thing that comes to mind
290
00:15:47,160 --> 00:15:52,080
is to simply select header like this, right?
291
00:15:52,080 --> 00:15:56,780
And so here is that new property called background color.
292
00:16:01,048 --> 00:16:03,610
And here let's use another nice gray color,
293
00:16:03,610 --> 00:16:04,913
which is F7F7F7.
294
00:16:07,680 --> 00:16:11,360
So again, you can see that the colors in the three colors,
295
00:16:11,360 --> 00:16:16,080
so the three main RGB channels are exactly the same.
296
00:16:16,080 --> 00:16:19,140
And by the way, here in the color picker,
297
00:16:19,140 --> 00:16:23,620
no matter what color you're in here in this color slider
298
00:16:23,620 --> 00:16:27,520
here on the left there is always this shade of grays.
299
00:16:27,520 --> 00:16:29,490
So if you start here from the top,
300
00:16:29,490 --> 00:16:32,260
you see the white that I showed you in this slide.
301
00:16:32,260 --> 00:16:36,090
And at the very top, you get then to black.
302
00:16:36,090 --> 00:16:36,950
Okay?
303
00:16:36,950 --> 00:16:39,360
So you can always get a gray color
304
00:16:39,360 --> 00:16:42,960
if you move the slider here at the very extreme
305
00:16:42,960 --> 00:16:45,350
of this left side here.
306
00:16:45,350 --> 00:16:48,950
But now let's go to F7F7, which is a color,
307
00:16:48,950 --> 00:16:52,400
which is nice to memorize and nice to use.
308
00:16:52,400 --> 00:16:56,830
So very subtle gray, maybe you cannot even see it here,
309
00:16:56,830 --> 00:16:59,360
but hopefully you will see it on your screen.
310
00:16:59,360 --> 00:17:01,360
Now, the problem here is that not only,
311
00:17:01,360 --> 00:17:04,070
our page header got the gray color,
312
00:17:04,070 --> 00:17:05,723
but also this other header.
313
00:17:06,670 --> 00:17:09,540
So maybe you could see that coming.
314
00:17:09,540 --> 00:17:13,800
And so the solution to that is to give this header a name
315
00:17:13,800 --> 00:17:16,510
and then style only this header.
316
00:17:16,510 --> 00:17:19,900
Now there's only this one header that we want to style,
317
00:17:19,900 --> 00:17:22,690
and so we could use an ID here,
318
00:17:22,690 --> 00:17:25,310
but given what I explained in the last lecture,
319
00:17:25,310 --> 00:17:28,253
let's not do that, and that's simply use a class.
320
00:17:29,760 --> 00:17:32,453
Let's call it main header.
321
00:17:33,860 --> 00:17:35,010
Let me copy it
322
00:17:37,490 --> 00:17:42,060
and replace this header with the main header class.
323
00:17:42,060 --> 00:17:46,670
And indeed now only this one here got this gray color.
324
00:17:46,670 --> 00:17:48,583
Let's just get rid of this test.
325
00:17:50,230 --> 00:17:51,303
And here we go.
326
00:17:52,580 --> 00:17:53,413
Nice.
327
00:17:53,413 --> 00:17:55,347
And if you can't really see this background color,
328
00:17:55,347 --> 00:17:58,270
then just use your color picker
329
00:17:58,270 --> 00:18:01,320
to just use some other shade of gray.
330
00:18:01,320 --> 00:18:02,270
All right.
331
00:18:02,270 --> 00:18:05,300
And this video is already running quite long,
332
00:18:05,300 --> 00:18:08,610
but let's still talk about another property here,
333
00:18:08,610 --> 00:18:10,890
which is about borders.
334
00:18:10,890 --> 00:18:15,010
So what I want to do next is to add some border
335
00:18:15,010 --> 00:18:18,370
to these related posts here.
336
00:18:18,370 --> 00:18:22,433
So basically to make them now look something like this.
337
00:18:23,550 --> 00:18:24,383
All right?
338
00:18:24,383 --> 00:18:27,260
So we have at the bottom and at the top here,
339
00:18:27,260 --> 00:18:28,323
this blue border.
340
00:18:29,650 --> 00:18:32,370
So that's not hard to do at all.
341
00:18:32,370 --> 00:18:34,933
So let's just see what's the element here.
342
00:18:35,940 --> 00:18:37,263
And it is this slide.
343
00:18:38,350 --> 00:18:40,770
So let's just select it here
344
00:18:43,640 --> 00:18:45,523
using this element selector.
345
00:18:46,940 --> 00:18:50,250
So element selector is basically when we simply use the name
346
00:18:50,250 --> 00:18:52,640
of the element to select it.
347
00:18:52,640 --> 00:18:53,480
Okay?
348
00:18:53,480 --> 00:18:56,390
So this year is the class selector with a dot.
349
00:18:56,390 --> 00:18:58,920
This is the ID selector with the hash.
350
00:18:58,920 --> 00:19:01,330
And when we simply use the name of the element,
351
00:19:01,330 --> 00:19:04,170
we call that the element selector.
352
00:19:04,170 --> 00:19:06,930
Now let's start by actually giving it the same
353
00:19:06,930 --> 00:19:08,033
background color.
354
00:19:09,510 --> 00:19:11,170
So background color
355
00:19:11,170 --> 00:19:14,270
and then we use the one that we used before.
356
00:19:14,270 --> 00:19:16,720
And VS code is actually very helpful here
357
00:19:16,720 --> 00:19:20,720
because it scans the CSS document for the files
358
00:19:20,720 --> 00:19:22,070
that we're already using
359
00:19:22,070 --> 00:19:25,870
so that we can very easily use the same ones.
360
00:19:25,870 --> 00:19:30,200
And then here, let's now talk about the border.
361
00:19:30,200 --> 00:19:31,700
So border,
362
00:19:31,700 --> 00:19:35,440
and now at this property is actually a special property
363
00:19:35,440 --> 00:19:38,420
because it accepts multiple values.
364
00:19:38,420 --> 00:19:42,970
So let's define the width of the border as five pixels,
365
00:19:42,970 --> 00:19:45,733
the style of the border as solid,
366
00:19:47,770 --> 00:19:51,160
and then the color of the border as,
367
00:19:51,160 --> 00:19:55,010
that color that we already use before, so this blue.
368
00:19:55,010 --> 00:19:56,280
Okay?
369
00:19:56,280 --> 00:19:57,530
Let's just give it a safe
370
00:19:57,530 --> 00:19:59,460
and then I will explain a little bit more
371
00:19:59,460 --> 00:20:00,833
why it works this way.
372
00:20:01,950 --> 00:20:05,790
And indeed here is all blue border.
373
00:20:05,790 --> 00:20:06,623
Beautiful.
374
00:20:08,250 --> 00:20:11,120
So going back here to this border property,
375
00:20:11,120 --> 00:20:13,810
this is actually a special kind of property.
376
00:20:13,810 --> 00:20:17,100
So it's called a shorthand property because
377
00:20:17,100 --> 00:20:19,160
we can just use one property
378
00:20:19,160 --> 00:20:21,900
for defining three different properties.
379
00:20:21,900 --> 00:20:26,170
So we could also individually style the border width,
380
00:20:26,170 --> 00:20:29,720
border style and border color properties.
381
00:20:29,720 --> 00:20:32,410
But usually we do it all in one run
382
00:20:32,410 --> 00:20:34,823
and simply define everything at the same time.
383
00:20:36,040 --> 00:20:39,360
Now here, you can define a lot of different keywords.
384
00:20:39,360 --> 00:20:43,533
For example, dotted is always a possibility.
385
00:20:45,380 --> 00:20:48,400
So this will look something like this.
386
00:20:48,400 --> 00:20:53,400
You can use dashed as well, which will look like this.
387
00:20:54,330 --> 00:20:59,330
But usually I never used those. I always go for solid.
388
00:21:00,570 --> 00:21:01,433
Okay.
389
00:21:02,400 --> 00:21:04,970
So this it gives us the entire border
390
00:21:04,970 --> 00:21:07,290
around the entire element.
391
00:21:07,290 --> 00:21:11,200
However, we only want the border at the top and the bottom.
392
00:21:11,200 --> 00:21:15,760
And so instead of defining the border property like this,
393
00:21:15,760 --> 00:21:19,310
there are also special variants of this property.
394
00:21:19,310 --> 00:21:22,350
So we can also say border top.
395
00:21:22,350 --> 00:21:24,700
And so this, as you might expect,
396
00:21:24,700 --> 00:21:29,020
we'll only style the border at the top side of the element.
397
00:21:29,020 --> 00:21:30,203
So just like this.
398
00:21:31,920 --> 00:21:32,920
Okay?
399
00:21:32,920 --> 00:21:36,360
Then let's select all of this and paste it here
400
00:21:36,360 --> 00:21:39,163
because we also want the border at the bottom.
401
00:21:40,160 --> 00:21:43,460
So easy enough border bottom.
402
00:21:43,460 --> 00:21:45,963
Give it a safe, and here we go.
403
00:21:46,810 --> 00:21:49,720
And just for the sake of completeness,
404
00:21:49,720 --> 00:21:54,720
we can also say border left and border right.
405
00:21:56,880 --> 00:22:00,310
And so then we will be back to square one
406
00:22:00,310 --> 00:22:03,250
where we have the borders on all the four sides.
407
00:22:03,250 --> 00:22:05,930
And so of course, this doesn't make sense
408
00:22:05,930 --> 00:22:08,690
then we would simply use the border property.
409
00:22:08,690 --> 00:22:11,820
These ones we don't want anyway.
410
00:22:11,820 --> 00:22:15,620
And so we are back to this result.
411
00:22:15,620 --> 00:22:16,453
All right.
412
00:22:16,453 --> 00:22:20,330
And this is how we work with colors in CSS.
413
00:22:20,330 --> 00:22:23,240
Now let me just quickly mention that we can also use
414
00:22:23,240 --> 00:22:26,400
these predefined color names just as we did
415
00:22:26,400 --> 00:22:29,263
in the very beginning with the color of blue.
416
00:22:30,810 --> 00:22:33,340
So quickly show that to you.
417
00:22:33,340 --> 00:22:36,550
So let's say that we wanted to set a background color
418
00:22:36,550 --> 00:22:38,430
for the entire webpage.
419
00:22:38,430 --> 00:22:42,250
So that's also possible simply by adding a style
420
00:22:42,250 --> 00:22:43,563
to the body.
421
00:22:44,980 --> 00:22:49,980
So we can just do background color like this,
422
00:22:51,316 --> 00:22:54,860
and here we can specify one of these names.
423
00:22:54,860 --> 00:22:56,720
So if I give it a safe,
424
00:22:56,720 --> 00:23:01,119
then everything has this very beautiful blue color
425
00:23:01,119 --> 00:23:02,450
as the background.
426
00:23:02,450 --> 00:23:06,440
Except of course the elements that we specifically gave
427
00:23:06,440 --> 00:23:08,650
another background color.
428
00:23:08,650 --> 00:23:09,483
Right?
429
00:23:11,130 --> 00:23:12,880
Or we could use something else.
430
00:23:12,880 --> 00:23:16,610
So usually if you just start writing some color name,
431
00:23:16,610 --> 00:23:20,370
you will get a lot of suggestions here from VS code
432
00:23:20,370 --> 00:23:22,823
and then you can select one of them like this.
433
00:23:24,210 --> 00:23:25,043
Okay?
434
00:23:25,043 --> 00:23:26,340
But of course we don't want that
435
00:23:26,340 --> 00:23:29,750
So let's just comment out this code by hitting comment
436
00:23:29,750 --> 00:23:34,160
or control slash, and then we are back to normal.
437
00:23:34,160 --> 00:23:34,993
Okay.
438
00:23:34,993 --> 00:23:38,350
And now, just to consolidate this knowledge a little bit,
439
00:23:38,350 --> 00:23:42,120
I suggest you to experiment with these three properties
440
00:23:42,120 --> 00:23:43,570
that we just learned.
441
00:23:43,570 --> 00:23:47,360
For example, by adding borders to some more elements,
442
00:23:47,360 --> 00:23:49,810
like some headings or some lists,
443
00:23:49,810 --> 00:23:52,410
and also changing some more text colors
444
00:23:52,410 --> 00:23:56,400
and especially important would also be to play around
445
00:23:56,400 --> 00:24:00,350
with the color picker a little bit on your own.
446
00:24:00,350 --> 00:24:03,030
So just take 10 or 15 minutes to do that
447
00:24:03,030 --> 00:24:05,563
and then I see you in the next video.
32922
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.