Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
Welcome back. 2
2
Let's now finally learn something new in CSS. 3
3
Which is exactly why you came to this course, right? 4
4
Now, as in all my other courses, 5
5
in all the coding lectures, 6
6
I always have this slide called 7
7
What You Will Learn in this Lecture. 8
8
And I found that students really appreciate 9
9
this quick lecture summary, 10
10
so that they can later come back to the lecture 11
11
and know if it contains exactly what they are looking for 12
12
or not. 13
13
And that's why I decided to continue this tradition 14
14
in this course. 15
15
In this lecture, you're gonna learn 16
16
the best way to perform a basic reset 17
17
using the universal selector. 18
18
And how to set up project-wide font definitions. 19
19
This might not be really new to you, 20
20
but we still have to do this 21
21
whenever we start a new project. 22
22
Now, what probably is new to you, is to clip parts 23
23
of elements using the new clip-path property. 24
24
And so that's the first real new modern CSS 25
25
you're gonna learn. 26
26
Let's do that right now. 27
27
All right, so we're back in the code editor 28
28
that I showed you before. 29
29
In this screen we have always the code editor 30
30
and then I have here another screen on the side 31
31
where I keep the webpage open 32
32
so we can check on the work that we've been doing. 33
33
Now this here is the final webpage 34
34
that I also will keep open as a reference 35
35
so that we can see always what to do next. 36
36
And so let's now actually open the website document 37
37
that we're gonna work on. 38
38
So it's this index.html, of course, in the project folder. 39
39
So in my case, it's on the desktop, 40
40
but maybe in your case it's somewhere else, 41
41
but let's go open this index.html file for now. 42
42
And of course it's still empty 43
43
because we didn't write any code yet, right? 44
44
Now later on we're gonna open this index.html 45
45
in a slightly different way. 46
46
We're basically gonna create a small local web server. 47
47
But for now this works just fine. 48
48
All right, so let's go back now to the editor. 49
49
Now to start, let's write the html for the header element. 50
50
Just for this part. This green, big element. 51
51
All of this will be our header. 52
52
For now, we're only gonna concentrate on 53
53
the background image and on making this shape here, okay? 54
54
That's what we're gonna focus on in this lecture. 55
55
We're gonna use the HTML5 header element. 56
56
And we're also going to give it a class called header. 57
57
If you're wondering why we're giving it a class name, 58
58
instead of just selecting it in the CSS 59
59
using the header element selector, 60
60
it's because you want a class name 61
61
on each and every element here in the html. 62
62
But we're gonna talk a bit more about CSS architecture 63
63
later in the course, where all of this will make sense. 64
64
Just for now, let's simply put some text here. 65
65
So, some text. 66
66
And that's enough for the html for now. 67
67
Remember we just want this big box with the background image 68
68
and the color and then that shape that we just saw, okay? 69
69
Let's now head over to our CSS file 70
70
and start writing some CSS. 71
71
Now the first thing I'm gonna do 72
72
is to perform a basic reset. 73
73
And maybe if you took my other CSS course, 74
74
then you might remember that I used something called 75
75
Normalize that CSS in order to make a cross browser reset. 76
76
So in order to make every browser render the page 77
77
in the exact same way. 78
78
Now doing so is still valid, but I found that browsers 79
79
are actually getting better and better 80
80
and more consistent in the way that they render a website. 81
81
And so that's no longer really necessary, 82
82
and so I don't do it anymore. 83
83
Let's just do a simple reset using the universal selector. 84
84
Just like this. 85
85
The universal selector will select each and every element 86
86
on the page, and then apply these declarations here to it. 87
87
We want a margin on all of them of zero pixels 88
88
and of course also a padding of zero. 89
89
By default, browsers apply a certain margin, 90
90
or a certain padding, to some elements. 91
91
For example, an H1 element, so the main heading, 92
92
there's always some margin in it. 93
93
And we don't want any of that. 94
94
This allows us basically to start clean, 95
95
without the browser adding any margins or paddings, 96
96
that we don't want, to our elements. 97
97
Another thing that we're gonna do, 98
98
is to set a box sizing property to border box. 99
99
Border. Box. 100
100
And if you're not familiar with box sizing border box, 101
101
what this does is to change the box model 102
102
so that the borders and the paddings are no longer added 103
103
to the total width or the total height 104
104
that we specify for a box. 105
105
Without this, any paddings and borders 106
106
are added to the height or the width of an element 107
107
which really isn't helpful for us, 108
108
and so with this, we're getting rid of that behavior. 109
109
All right. And next, let's set some overall font properties 110
110
for the entire webpage. 111
111
This time, we're not going to do it 112
112
in the universal selector, but in the body element selector. 113
113
And why do we do it this way? 114
114
Well, we do it because the properties related to font 115
115
are usually inherited, 116
116
so we're using the power of inheritance here. 117
117
I'm gonna explain everything there is about inheritance 118
118
in the next section. 119
119
We have a whole lecture just about inheritance in CSS. 120
120
What you need to know for now, 121
121
is that we set, for example, the font family 122
122
on the body element, which is basically the parent element 123
123
of all the other elements. 124
124
Then this font family will get inherited, 125
125
but all the child elements of the body. 126
126
And doing it this way is actually more efficient, 127
127
and it's a better practice than to just put all of this 128
128
in the universal selector up here. 129
129
We never do that. 130
130
Everything related to font, 131
131
we always specify it here in the body selector. 132
132
We set the font family to Lato. 133
133
And if that's not available, then just some Sans Serif. 134
134
I can use Lato because I already included it here 135
135
in the html. 136
136
As I said in the beginning, this comes from Google fonts, 137
137
and it's a font that I have already included. 138
138
If you're not familiar with this, it's really simple. 139
139
You can just go to Google Fonts and find it out. 140
140
I included Lato with the font weights of 141
141
100, 300, 400, 700 and 900. 142
142
Let's set the overall font weight to just 400. 143
143
Font weight. 400. 144
144
Also the overall font size should be 16 pixels 145
145
and the line height of, let's say, 1.7. 146
146
So basically line height 1.7 means that 147
147
it's 1.7 times bigger than the predefined line height, 148
148
that we would have without this. 149
149
We're using 16 pixels here for now, 150
150
but we're actually going to change this later 151
151
to use a better technique, 152
152
but for now, let's go with these pixels. 153
153
Something else we can set here is the overall text color, 154
154
which I'm sure you also know how to do it. 155
155
And it's just color. 156
156
And then the color that I chose for this text 157
157
is this gray, 777. 158
158
And here in my text territory actually have 159
159
an extension, which then nicely highlights the color. 160
160
This is how the color looks like, this gray 777. 161
161
It also does it up here in the comments. 162
162
These are the greens and you can already see 163
163
how they look like because of what this extension does. 164
164
And with this code, we just performed a basic reset 165
165
and we also set the project-wide font definitions 166
166
here in the body selector 167
167
because they will all be inherited to their child elements. 168
168
With that in place, 169
169
let's start formatting the header element. 170
170
And remember it has the header class. 171
171
We use the class selector and then header. 172
172
Let's just create some space here. 173
173
Let's start by defining the height, 174
174
and let's set it to 95vh. 175
175
In case you're not sure what this does, 176
176
it's basically we say that at every point, 177
177
the height of this box, of this element, 178
178
should be 95% of the viewport height. 179
179
Now we could put 100 here, 180
180
then the element would always be exactly the same height 181
181
as the viewport, but I chose to go with 95 182
182
to make it not 100%, but only almost 100%. 183
183
Let's now set the background image. 184
184
I start typing background, 185
185
but instead of having to write all the way until background, 186
186
and then image, I can just start writing image right now, 187
187
because the text editor will recognize 188
188
that I'm looking for background image. 189
189
You see, it already recognized that that's what I want. 190
190
And this will also work in your text editor. 191
191
You can just do the same and you don't have to write 192
192
all the codes, like background image, 193
193
when instead just back img and then it works. 194
194
Press enter and that's it. 195
195
The background image that we want 196
196
is here in the image folder. 197
197
It is called hero, I think. 198
198
Yeah, so that's the one we want, right? 199
199
You see? It's this one here. 200
200
And we specify an image by writing url 201
201
and then specifying the path to the image. 202
202
Now we're currently in the CSS folder, 203
203
so we first have to go one folder up 204
204
to go into the project folder. 205
205
And so it's ../ then, img, so image, 206
206
and then the name of the image, hero.jpg 207
207
And that's it. 208
208
So again, we were here in the CSS folder 209
209
and we went one level up to go into the project folder 210
210
so the Natours folder here, 211
211
and then from there we went into the image folder, 212
212
and then hero.jpg. 213
213
And now something else we should do 214
214
is to set the background size to cover, 215
215
which I'm sure you're also familiar with. 216
216
Again, I do this trick. 217
217
I just write back, then I start writing size, 218
218
return, and that's it. 219
219
And cover is what I want here. 220
220
And what cover does is that whatever the width of 221
221
the viewport, or the element, it'll always try to fit 222
222
the element inside of the box. 223
223
Let's now take a look on what that looks like. 224
224
This one is it. Refresh. And here we go. 225
225
So our background image adapts nicely to the viewport, 226
226
I hope. 227
227
And yeah, it does. 228
228
And you see here this white bar, 229
229
it's the remaining 5% of the viewport height. 230
230
100% would fill everything. 231
231
95 fills just up until this point. 232
232
And also here you can see the text, 233
233
the some text the we put 234
234
and it's already styled with the Lato font family, 235
235
with the gray color and the 16 pixels in size. 236
236
Now something else we could do here 237
237
is to set the background position. 238
238
Background position and we can set it to top. 239
239
Let's see what that does. 240
240
It looks like it did nothing, but actually it does. 241
241
Because what it does is to ensure that whatever 242
242
the viewport size is that this top of the image here 243
243
always stays at the top of the container. 244
244
So you see now here, as we go up, 245
245
the bottom of the image gets cropped, 246
246
but the top of the image stays the same, right? 247
247
So it's this, what I'm talking about. 248
248
Now we could change it, so let's actually use the DevTools 249
249
here right now. 250
250
Because this is a fundamental part of being a web developer 251
251
is using these Chrome DevTools. 252
252
Let's see what it would look like if we set it to bottom. 253
253
Now what happens is that the bottom stays the same 254
254
as we change the image size. 255
255
The bottom stays the same and it changes up there. 256
256
Now what we also can do is to set it to center. 257
257
What it will do now is to always stay at the center. 258
258
It will now probably crop out at the top and at the bottom. 259
259
So you see. Yeah, that's what happens now. 260
260
Basically, it's in the middle here now, 261
261
where it stays the same, but at the bottom and the top 262
262
it is cropped out. You see? 263
263
All right, but we of course want it at the top. 264
264
Next up, we want that nice green gradient 265
265
all over the image. 266
266
And how do we do that? 267
267
We use background image again, because to specify gradients, 268
268
we always use the background image property. 269
269
We already have the background image property here 270
270
with the image. 271
271
So what can we do? 272
272
We simply specify a second one. 273
273
And what we do is to use the comma. 274
274
Now we want the background to stay on top 275
275
and so it actually has to be first 276
276
background image that we specify. 277
277
We put a gradient here 278
278
and then comma, the image. Okay? 279
279
Let's put actually the linear gradient here. 280
280
Linear gradient and then the colors that we want. 281
281
And we actually have the colors up here, 282
282
so we start with the light green on one side. 283
283
I paste it here. 284
284
And then comma, and on the other side, the dark green. 285
285
Okay. Makes sense. 286
286
We have basically two background images, 287
287
one on top of the other. 288
288
The first one is the linear gradient 289
289
going from this color to this color. 290
290
And then after that, so basically below that, 291
291
is this hero image. 292
292
Now another parameter that we can specify 293
293
in the linear gradient is basically to where 294
294
the gradient should go. 295
295
We can say to right. 296
296
And so now CSS understands that it should start 297
297
on the left side and go to the right. 298
298
Let's see if that worked. 299
299
Close the DevTools and then reload. 300
300
And yeah, that's it. 301
301
So we have the gradient going from the left side. 302
302
But the first green, lighter one, going to the right side 303
303
with the darker green. 304
304
Now we could also say to top or to bottom or to left, 305
305
and we can also do something else, 306
306
which is specifying two directions. 307
307
So we say to right bottom. 308
308
And so now the gradient will go to the right bottom corner. 309
309
Starting probably at the left top. Right? 310
310
Let's see if that's what happens. 311
311
And yeah, I hope you saw it change. 312
312
So now it goes from here, all the way there. 313
313
Only one thing left to do 314
314
is to actually make the image below it visible, right? 315
315
And how can we do that? 316
316
Yeah, we have to change the opacity of these colors. 317
317
In order to do that, I can actually use the built in 318
318
color picker that I have here. 319
319
And I'm sure that your text editor, 320
320
if you're not using Visual Studio Code, 321
321
will do the same. 322
322
I just have to pull down this slider here, 323
323
then until it gives me an opacity of 08. 324
324
I'm sure you're familiar with this rgba syntax. 325
325
Basically, rgba means that we have here the R, G and B, 326
326
so red, green and blue 327
327
and then the opacity value in the end. 328
328
And this color picker does the conversion automatically, 329
329
so we no longer can use this hexadecimal annotation here, 330
330
so 28b485, but we have to change to rgba, okay? 331
331
I'm putting 80 here, 332
332
so basically 80% of the color is visible. 333
333
If you went down here to like 10%, 334
334
it will be almost transparent. 335
335
But we want 80% here. 336
336
This looks a bit confusing here, 337
337
so let's actually clean this up a bit. 338
338
Each argument has it's own line, 339
339
and then also this one on a separate line 340
340
so that it's easier to read a little bit. 341
341
Again, we have two background images. 342
342
First is gradient, going to right bottom 343
343
with these two colors. 344
344
And then the image below that. 345
345
So let's see if that's the effect that we want. 346
346
And yeah. That's pretty much how we want it to look like. 347
347
Let's check. Yeah. 348
348
That's actually almost what it looks like. 349
349
You see this small white thing here, 350
350
this small white border, 351
351
that goes around this entire webpage? 352
352
You see it? It's actually also here. 353
353
You can see that here it's light gray. 354
354
But here it's white. 355
355
This white thing goes around the entire webpage. 356
356
I think it gives everything a very nice look. 357
357
Let's do that as well. 358
358
It's actually really easy. 359
359
All we have to do is to put a padding 360
360
around the entire body. 361
361
Padding, 30 pixels. 362
362
The body element contains the entire webpage 363
363
and so if we set a padding here, 364
364
then this padding will get applied on the entire webpage. 365
365
Just like this. Here we go. 366
366
That's our 30 pixel padding here around the webpage. 367
367
This is not a case of inheritance, like we had here, 368
368
because the padding is not getting inherited. 369
369
All that's happening is that it's applying a 30 pixel 370
370
padding around the entire body. 371
371
And now the last piece of the styling 372
372
that we want to do for the header. 373
373
What we want is now this kind of wedge 374
374
that we can see here. 375
375
And what this is, is to simply clip, 376
376
clip out this part of the image 377
377
that would otherwise be here. 378
378
Okay? Let's now do that. 379
379
And for that, we use the really modern CSS property 380
380
called clip-path. 381
381
So, clip-path. 382
382
And what we're doing here is to specify a polygon 383
383
in which the image, or the element, will still be visible. 384
384
We use the polygon function. 385
385
So polygon. 386
386
And in here we define a bunch of coordinates 387
387
which define this polygon. 388
388
For now, let me just put some place holders here, 389
389
like X and epsilon. X and epsilon. 390
390
And we're gonna specify these later on. 391
391
Okay. X and epsilon. 392
392
But first, we need to take a look at the image to see 393
393
how it actually should work. 394
394
So this is our image, 395
395
and this is how we want the final version to look. 396
396
All right, so what are the four coordinates of this polygon 397
397
where we want the element to still be visible? 398
398
It's this one here, right? So we're gonna start here. 399
399
This one. Then here, this coordinate. 400
400
Then this one, this corner. 401
401
And then finally, this one. 402
402
All we need to specify these four corners 403
403
in order to obtain this polygon. 404
404
And we're gonna start here at the top left corner 405
405
and then move clockwise. 406
406
This one first, then this one, 407
407
then the third one, and then the final one. 408
408
In relation to this point here, 409
409
where do we want the first point to be? 410
410
We want it to be exactly here, right? 411
411
So we don't wanna move it anything in the X axis, 412
412
so it's just like this. This is X. 413
413
And we don't want it to move in the epsilon axis, 414
414
so also not this way. 415
415
It's just zero zero. 416
416
You want it to stay in the same place. 417
417
So zero and zero. Okay? 418
418
In the X direction we don't want it to change. 419
419
And in the epsilon direction, 420
420
we also don't want it to change. 421
421
Let's now take a look at the second point. 422
422
So this one here. 423
423
Counting from here, from the left side, 424
424
we want it to change in the X direction, right? 425
425
All the way until this point 426
426
we want the polygon to go, right? 427
427
And so what is this point here? 428
428
How far away is it from the left side? 429
429
We can simply say it's 100%. 430
430
So it's gonna be 100% of the width of this element 431
431
away from the left side, from here. 432
432
We can just say that X should be 100% 433
433
and our epsilon in the epsilon direction, 434
434
we don't wanna change it at all, right? 435
435
Okay. And now the third coordinate is this one. 436
436
It's the same in the X direction, right? 437
437
So it's still 100% in the X direction, 438
438
but now the epsilon is what changes here. 439
439
Let's just put some random number there, okay? 440
440
X is still the same, 100%. 441
441
And now from the top, we want it to be at some point. 442
442
Let's just say 50%. 443
443
Or we could also specify it as in pixels 444
444
or in any other unit that we want. 445
445
For example, I can say 200 pixels, okay? 446
446
All right. And now the last coordinate is this one here, 447
447
the fourth. 448
448
In X, we're back to zero here, right? 449
449
Because remember that this side here is the reference. 450
450
We don't move anything in the X direction, so this way. 451
451
We did move, however, in the epsilon direction, 452
452
so going from here, 453
453
we did all the way down to the end of the element. 454
454
So we want 100%. 455
455
In X it's zero and in epsilon it's 100%. 456
456
And that's it. 457
457
So let's see if this actually worked. 458
458
And now, here it is. 459
459
All right. Great. 460
460
These are the 200 pixels that we specified here 461
461
in this coordinate for the epsilon direction. 462
462
Let's now inspect this element. 463
463
And we can now change here some stuff 464
464
so that you can see how this changes. 465
465
Imagine that here for the second coordinate, 466
466
so this one here, we wouldn't put 100 pixels, 467
467
but let's say, sorry. 468
468
We wouldn't put 100%, but we would put let's say 500 pixels. 469
469
Okay, that makes sense, right? 470
470
Because we have 500 in the X direction 471
471
and zero in the epsilon direction. 472
472
Can also change that of course. 473
473
Let's say we have 100 pixels here, 474
474
then it look like that. 475
475
All right. 476
476
Now what I want you to try here 477
477
is to make a triangle of this. 478
478
Okay? 479
479
I'm pretty sure that after this explanation 480
480
you should already understand how it works, right? 481
481
Try to pause the video and try to do a triangle here, okay? 482
482
So, did you manage to make it work? 483
483
This is how I would do it. 484
484
Let's just get rid of all of this. 485
485
And now, the first coordinate 486
486
should be here in the center, right? 487
487
We have X 50% and on epsilon, 0%. 488
488
And now we want this bottom corner here, 489
489
so X is 100% and epsilon is also 100%, right? 490
490
And now finally it's this bottom corner here. 491
491
And so here we have X zero and epsilon is 100%. 492
492
So zero and 100%. 493
493
And here we go. So here we have our triangle, right? 494
494
So if you wanna make a triangle, it's like this. 495
495
Now you can do lots of different things with this 496
496
and there's actually a very cool tool 497
497
which is called Clippy, this one here. 498
498
And I'm gonna put it on my resource reference page 499
499
so that you can check it out later. 500
500
And here you just need to click on one of these. 501
501
Let's say we want a right arrow, like this. 502
502
To get a bit crazy. 503
503
And then all we have to do is to copy this CSS code here. 504
504
Now let's just copy these numbers 505
505
because we already have the clip-path property written out. 506
506
Just to make a final test, final experiment. 507
507
It works like this. Okay. 508
508
Now we have an arrow. 509
509
Okay, but we don't want any arrow. 510
510
We just want our element to look like in the example page. 511
511
And so here, what we will do, is not to specify a percentage 512
512
but a unit of viewport height. 513
513
Such as we did here for the height of the element. 514
514
In here, I will say 75% of the viewport height, okay? 515
515
So let's look how this looks like now. 516
516
And that's it. 517
517
Now if we change the viewport height, 518
518
it will also change dynamically. 519
519
This little interval here, right? 520
520
And if I close this completely, then it looks like this. 521
521
And it looks the exact same way as our original, right? 522
522
See. That's how it looks like. 523
523
Awesome. 524
524
I know this is a bit complicated to understand 525
525
this clip-path property and the polygon we have to write, 526
526
but try to wrap your head around it, 527
527
and then it's actually not so complicated. 528
528
I hope that this first coding lecture 529
529
of the course was quite fun 530
530
and that you already learned something new here. 531
531
We're already making great progress 532
532
and to continue with this header, 533
533
just come with me right to the next lecture. 534
534
See you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.