Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,110 --> 00:00:08,300
Now we've already used some CSS properties in order to apply CSS to our different HTML elements, but in
2
00:00:08,300 --> 00:00:13,220
this section we're going to do a deep dive into some of the most important CSS properties that you'll
3
00:00:13,220 --> 00:00:14,690
see and use.
4
00:00:14,720 --> 00:00:20,300
And we're going to start with CSS, color properties. Some of the color properties you've already seen
5
00:00:20,300 --> 00:00:21,410
previously.
6
00:00:21,530 --> 00:00:28,640
I've shown you how you can set the background color of a particular HTML element by using the background-color
7
00:00:29,180 --> 00:00:30,800
property,
8
00:00:30,800 --> 00:00:36,920
and previously we've been setting it to basic colors like red or blue or green.
9
00:00:37,040 --> 00:00:45,080
And remember that the way that the CSS rules work is the first part is the property.
10
00:00:46,280 --> 00:00:52,850
And the part that comes after the colon is the value that you want to set that property to.
11
00:00:52,880 --> 00:00:59,630
So in this case, we're setting the background color of the HTML element, which remember contains everything
12
00:00:59,630 --> 00:01:00,660
on our website,
13
00:01:00,660 --> 00:01:04,769
so the entire web page to a color of red.
14
00:01:04,769 --> 00:01:06,510
That's what that rule does.
15
00:01:06,690 --> 00:01:10,170
Now, there are different types of color properties.
16
00:01:10,170 --> 00:01:15,090
There's the background color, but you can also simply use the color property,
17
00:01:15,090 --> 00:01:19,080
and what this does is it sets the text color.
18
00:01:19,080 --> 00:01:21,900
So always check the MDN Docs
19
00:01:21,930 --> 00:01:25,200
if you're not sure which property does what.
20
00:01:26,370 --> 00:01:32,460
Notice that in this case, we've got two colors, which we've named red and blue,
21
00:01:32,490 --> 00:01:35,640
well, how do we know that we can use these colors
22
00:01:35,640 --> 00:01:37,380
and what exactly are they?
23
00:01:37,500 --> 00:01:39,810
Well, they're called named colors.
24
00:01:39,810 --> 00:01:47,910
And there's a whole bunch of them out there with poetic names like Cornflower Blue or Cadet Blue or
25
00:01:47,910 --> 00:01:51,390
Dim Gray or Olive Drab, etcetera.
26
00:01:51,390 --> 00:01:56,340
And you can find all of them by, of course, going to the Developer Documentation.
27
00:01:56,430 --> 00:02:03,140
If you Google for MDN Docs named color, the first link should take you to this web page.
28
00:02:03,150 --> 00:02:08,580
Alternatively, you can use this URL as well, and the syntax is pretty simple
29
00:02:08,580 --> 00:02:16,080
you simply use the name of the color and if you scroll through this table you'll see all the different
30
00:02:16,080 --> 00:02:16,740
colors.
31
00:02:16,740 --> 00:02:20,880
And don't worry too much about the CSS Level 1 or Level 2 or Level 3,
32
00:02:20,910 --> 00:02:24,870
it just describes historically when each color was introduced.
33
00:02:24,870 --> 00:02:28,330
So these were introduced first because it's basically the rainbow.
34
00:02:28,330 --> 00:02:35,650
And then over time we got some more fun colors like cyan and dark khaki and all of these different colors.
35
00:02:35,650 --> 00:02:42,490
So you can simply copy the name of the color and paste it into your code and you'll be able to see that
36
00:02:42,490 --> 00:02:44,380
rendered in your website.
37
00:02:44,530 --> 00:02:49,900
Of course, even though there's many colors available in the default CSS named colors,
38
00:02:49,900 --> 00:02:54,460
But you still sometimes might want to have a more unique color palette.
39
00:02:54,460 --> 00:02:56,410
So what do you do in that case?
40
00:02:56,410 --> 00:03:01,510
Well, one of my favorite color palettes is colorhunt.co.
41
00:03:01,900 --> 00:03:09,070
It's a free tool that's created by designers for designers and of course, for us as well.
42
00:03:09,250 --> 00:03:15,610
Here you've got professionally designed color palettes for colors stacked together that would look perfect
43
00:03:15,610 --> 00:03:16,840
on any website.
44
00:03:16,870 --> 00:03:22,450
You can imagine that if you select any of these random websites, maybe this could be the background
45
00:03:22,450 --> 00:03:23,500
color of the website.
46
00:03:23,500 --> 00:03:28,090
This could be an h1 color, this could be a subtitle or h2 color.
47
00:03:28,090 --> 00:03:33,310
You have accent tones, you have main tones, and you can use all of these colors in your website.
48
00:03:33,310 --> 00:03:38,110
But how do we use them if we don't have a name that's attached to it?
49
00:03:38,110 --> 00:03:40,960
Instead, we've got all these numbers and letters,
50
00:03:40,960 --> 00:03:42,730
what exactly are these?
51
00:03:42,760 --> 00:03:51,820
Well, these are "hex codes" and they are a way of representing a larger number code for that particular
52
00:03:51,820 --> 00:03:52,450
color.
53
00:03:52,450 --> 00:04:00,010
So, for example, in this case, this is a color purple which is formed of three fractions, red,
54
00:04:00,010 --> 00:04:01,030
green and blue.
55
00:04:01,090 --> 00:04:04,720
And these are colors out of 255.
56
00:04:04,720 --> 00:04:15,160
So if you imagine a fraction, 93 out of 255 red, 56 out of 255 green 145 out of 255 blue.
57
00:04:15,160 --> 00:04:21,160
And when you mix all three of these primary colors, you can get so many different types of shades.
58
00:04:21,160 --> 00:04:24,550
So in this case, we've got 93, 56, 145,
59
00:04:24,580 --> 00:04:37,300
so 93 out of 255, 56 green out of 255 and 145.
60
00:04:37,300 --> 00:04:44,860
So a little bit more blue and we end up with exactly the same shade as this purple you see right here
61
00:04:45,370 --> 00:04:49,480
Converting that RGB into a hex code,
62
00:04:49,480 --> 00:04:52,600
so a different way of representing that number,
63
00:04:52,600 --> 00:04:55,210
we get this particular hex code.
64
00:04:55,210 --> 00:04:56,860
What does this mean for you?
65
00:04:56,860 --> 00:05:01,780
Well, when you're using something like Color Hunt and you want to apply these different colors to your
66
00:05:01,780 --> 00:05:08,080
website, you can simply copy the hex code and use it instead of the name.
67
00:05:08,080 --> 00:05:14,770
And even on the MDN Docs for the named colors, you can see their hex codes lined up next to the names,
68
00:05:14,770 --> 00:05:18,220
and in code it looks pretty much exactly the same.
69
00:05:18,220 --> 00:05:20,860
Instead of the name, you just put the hex code.
70
00:05:21,370 --> 00:05:23,650
So now it's time to try an exercise.
71
00:05:23,680 --> 00:05:30,730
Go ahead and download this zip file from this current lesson, extract it and open it inside VS Code.
72
00:05:30,910 --> 00:05:36,970
Once you're here, you should see it's a pretty simple website with just two elements inside the body,
73
00:05:37,210 --> 00:05:38,950
a h1 and a h2.
74
00:05:38,950 --> 00:05:44,740
And if we look at the preview, then you can see it's clearly a drab, black and white world.
75
00:05:44,860 --> 00:05:48,370
We're going to change all of that by adding in CSS colors.
76
00:05:48,370 --> 00:05:54,610
So you've got five steps that you need to complete here and you should follow them one by one and by
77
00:05:54,610 --> 00:06:00,010
the end of all five steps, you should have a website that looks something like this with lots of different
78
00:06:00,010 --> 00:06:02,980
colors and different background colors as well.
79
00:06:03,160 --> 00:06:05,980
Pause the video now and give this challenge a go.
80
00:06:09,620 --> 00:06:10,040
All right.
81
00:06:10,040 --> 00:06:12,500
So let's walk through the solution together.
82
00:06:12,680 --> 00:06:20,330
We've got the background-color of the body, which is set to antiquewhite, which is this color right
83
00:06:20,330 --> 00:06:20,890
here.
84
00:06:20,900 --> 00:06:25,400
And we've got the text color of the h1 set to white-smoke,
85
00:06:25,430 --> 00:06:29,430
but you can also set the background color of the h1.
86
00:06:29,450 --> 00:06:35,390
It's a property that's available on any of the elements and it simply takes the existing area of that
87
00:06:35,390 --> 00:06:37,700
element and colors the background.
88
00:06:37,910 --> 00:06:41,870
Now, that might have required a little bit of lateral thinking, but hopefully you got there in the
89
00:06:41,870 --> 00:06:42,440
end.
90
00:06:42,440 --> 00:06:49,910
And notice how in the h1 we've got all named colors and in the h2, I've asked you to use hex
91
00:06:49,910 --> 00:06:55,760
colors and this is just so that you have practice adding colors using the two different methods.
92
00:06:56,630 --> 00:06:58,280
Hopefully you got there in the end.
93
00:06:58,280 --> 00:07:05,090
Once you're ready, head over to the next lesson and let's learn more about formatting fonts using CSS.
9405
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.