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
We're almost done building the first 2
2
section of our page, but what's missing is this cool 3
3
animated button that I showed you right at the beginning. 4
4
So let's go build that. 5
5
By coding up this button, you will learn techniques 6
6
that are going to be useful in countless situations 7
7
in the future. 8
8
So you're going to learn what pseudo-elements 9
9
and pseudo-classes are and why they are important. 10
10
How and why to use the after pseudo-element 11
11
and how to build a creative hover animation effect 12
12
using the transition property. 13
13
So this lecture is probably going to be rather long 14
14
but I promise you it's going to be totally worth it. 15
15
So the button that I'm talking about is this one here. 16
16
And so it has this nice effect you see 17
17
where it looks like it's getting bigger 18
18
and then in the end it fades out after like 19
19
half a second or something, you see? 20
20
So this is what we're going to build. 21
21
So it moves up a little bit and 22
22
creates this shadow beneath it 23
23
and so it looks like it's moving up 24
24
in direction to the user. 25
25
So let's check it again. 26
26
So it's like it's really moving up, 27
27
that's why the shadow then appears. 28
28
Now, look what happens when we click it, 29
29
so it goes down a little bit and the shadow also 30
30
disappears a little bit as if we were really 31
31
pushing it towards the page. 32
32
Want to see it again? 33
33
So we hover it, it elevates, and then as we click it, 34
34
it looks like it's going back down, 35
35
and you can see it because it moves down 36
36
and because the shadow gets a little bit smaller. 37
37
So you see? 38
38
There it is. 39
39
And actually moves down, but let's see it again and 40
40
there it is, right? 41
41
So let's first code up that part 42
42
where this functionality happens 43
43
and then later we're going to care about this white part 44
44
that looks like it's like flying out or something, 45
45
it's growing bigger and bigger and then disappears. 46
46
So back to our markup here, 47
47
remember that I was saying that we were going to 48
48
add something here to this text box 49
49
and what I mean is, of course, this button. 50
50
So the button will be an anchor element, 51
51
so a for now, with an href of nothing, 52
52
so leading to nothing, which is this hash symbol 53
53
and then of course, we need to give it some class, 54
54
and I'm going to call it, as usual, button, 55
55
but at the same time, I'm giving it another class, 56
56
calling button, white, because we're going to have 57
57
multiple buttons on the page, some will be white 58
58
some will be green, but most of the functionality 59
59
is the same, only the color changes and so I'm going 60
60
to put the styles about the color here in this class 61
61
and the stuff that doesn't change 62
62
from the white to the green button in this button class. 63
63
So we've done this before, at least in my other HTML course 64
64
and so this should be nothing new to you, 65
65
it's just a good practice. 66
66
Alright, and the text, which we have on this link, 67
67
on this button, is discover our tours, 68
68
just like this. 69
69
And so let's now start styling the button element down here. 70
70
So you see our CSS file is getting rather long, 71
71
we're already at 121 lines here, but don't worry, 72
72
we're going to think about architecture 73
73
and all that stuff a bit later. 74
74
So for now, in this section, we're just focusing on 75
75
getting this code ready here and 76
76
getting this header element ready 77
77
and we're going to think about organizational aspects 78
78
of our code a bit later. 79
79
So with this, we select a button element 80
80
but since it's a link, I'm sure you already know 81
81
that we should do it like this. 82
82
Alright, and what is this? 83
83
So this here is a pseudo-class, it's the link pseudo-class. 84
84
And pseudo-classes are a special state of a selector. 85
85
So this link here is a state of the button selector. 86
86
So like when a user hovers an element, or when a checkbox 87
87
is clicked or if we want to select a last-child, 88
88
and many other possibilities. 89
89
So we use pseudo-classes to style elements 90
90
under a special condition. 91
91
And it's a very important concept 92
92
that we're going to use all the time. 93
93
So the link is a special state of a selector when it is 94
94
an anchor element so it functions as a link. 95
95
But there's also the visited state. 96
96
So button visited. 97
97
So this is the state when the user has already clicked 98
98
on the button once before and then sees the button again, 99
99
so that's the visited state. 100
100
And I'm sure that you know that for example, if we don't 101
101
style a link at all, it will appear blue in the beginning 102
102
and then once we click on it once, when we see it again, 103
103
then it will be purple. 104
104
So that's the default styling of links 105
105
in most of the browsers. 106
106
Now we don't want this, we want the visited state to 107
107
look at exactly like the link state, so the normal state 108
108
of our links and so we just put them together. 109
109
Now the first thing that we're going to do is to say 110
110
that we want the text to be uppercase, 111
111
text transform uppercase. 112
112
We want there to be no text decoration. 113
113
Let's actually take a look so we can see 114
114
what exactly we want to change. 115
115
So here we go. 116
116
So we don't want, of course, this color 117
117
and we don't want this underline, 118
118
so let's get rid of it. 119
119
So, text decoration and I'm sure you 120
120
already know all of this, 121
121
that's why these properties that are not really new to you, 122
122
I'm not really explaining what they're doing, okay? 123
123
And then the text we want to be gray. 124
124
Now remember that we're going to have multiple colors 125
125
for the button and so in the white button, 126
126
the text will be this dark gray, 127
127
but in the green button, it will probably be white. 128
128
And so that's something that we have to do 129
129
in this external class. 130
130
So let me already create that actually, 131
131
so it's called button white, and so here we're going 132
132
to have a background color of white, of course, 133
133
background color, and just so I did this trick 134
134
where I just write a couple of letters and then the 135
135
text editor figures our which property I want 136
136
and this way I have to type less code. 137
137
So white as we saw already, FFF, 138
138
and the color should be 777 as we already used before. 139
139
Now we also want some padding around the button, of course, 140
140
so let's specify that as well. 141
141
And once again, I'm sure you're already familiar with how 142
142
the shortened property of padding works. 143
143
So we can specify only one value and then it will 144
144
apply everywhere, so top, bottom, left, and right 145
145
or we can also write two values. 146
146
Then the first one will be for top and bottom 147
147
and then second one will be for left and right. 148
148
So let's say 15 pixels and 40 pixels. 149
149
So now we have a padding at the top and at the bottom of 150
150
15 pixels and left and right, 40 pixels. 151
151
And we could also write four numbers. 152
152
Then the first one would be top, the second would be right, 153
153
the third one would be the bottom, 154
154
and the fourth one would be for the left side. 155
155
Okay, now check this out, 156
156
but I will tell you already that it's not going to work as 157
157
expected because it's occupying here this space 158
158
on the top of this other text where it shouldn't. 159
159
That's because it's right now, an inline element. 160
160
So this button here is right now an inline element 161
161
because it's simply text, but we should display it 162
162
as an inline block. 163
163
And this way the box model works on this element as if 164
164
was just a normal block element, okay? 165
165
So we should always do this if we want to 166
166
give some paddings or some heights 167
167
or width to elements, okay? 168
168
Now another thing that I noticed here, 169
169
let me just refresh this, so now it has its own space. 170
170
Another thing that we want is this actually here to be in 171
171
the middle of this box, right? 172
172
So how could we do that? 173
173
How could we achieve this button to be 174
174
in the center of the box? 175
175
Do you think we should use absolute positioning 176
176
or transforms like we did before? 177
177
Well I don't think so because 178
178
that would really be overkill. 179
179
It would be way to much for this very simple problem. 180
180
So this is an inline block element and 181
181
so it's treated as if it was text. 182
182
And so if it's text and we want it to be at the center 183
183
of this box, all we have to do is to set the text box, 184
184
I believe it's called. 185
185
Exactly, it's text box. 186
186
All we have to do is to set its text align property 187
187
to the center and that's it. 188
188
So now it's going to center the text 189
189
that is inside of the box, including of course, the button. 190
190
So just to be sure, yeah, here it goes. 191
191
And since we're here, let's also add here some white 192
192
space between this heading element and the button. 193
193
So how do we do white space? 194
194
Exactly, we use the margin property. 195
195
And in this case we just want margin at the bottom, 196
196
we say margin bottom and let's say we want 60 pixels. 197
197
Alright. 198
198
I'm not going to check it right now, 199
199
we're going to check it later on. 200
200
So this is link in the visited state. 201
201
Now let's take care actually of the hover state. 202
202
So button hover, so another pseudo-class to select 203
203
a different and special state of this element. 204
204
So what do we want to happen, remember? 205
205
The first thing is for this element to move up. 206
206
So how can we do that? 207
207
We use transform, such as we did before. 208
208
So you see transform is something really, really important. 209
209
It's an extremely important property that we're 210
210
using all the time to create cool and modern effects, 211
211
where elements move around or even rotate or stuff, 212
212
so transform is really important. 213
213
So now we want to translate it and we want it to move up. 214
214
So which direction is that? 215
215
X or upsilon? 216
216
And it's right, it's direction upsilon, of course. 217
217
And we want it to move up so we use a negative value 218
218
and that's because in CSS, the upsilon axis moves from 219
219
the top to the bottom, so it's like 220
220
from the top to the bottom. 221
221
And if you want to move up, we have to go the 222
222
other way around and so it's negative. 223
223
So to go up, it's a negative value. 224
224
So negative, minus three pixels in this case. 225
225
So that's for the hover. 226
226
Now when we clicked it, remember it looked a bit different. 227
227
So it's the active state remember, when we click an element 228
228
then that's called the active state. 229
229
So it's the active pseudo-class. 230
230
So remember what it looked like when we clicked it? 231
231
Again, it's a translate because again, it moved 232
232
and this time we're only moving it one pixel up. 233
233
So this one pixel up, so this minus one pixel 234
234
is in relation to the initial state, so to the link state, 235
235
not to the hover. 236
236
So it's not minus one pixel 237
237
in relation to the hover state, but 238
238
it's always here related to the initial link state, okay? 239
239
So let's check that out. 240
240
So the margin is there and we hover so it goes up. 241
241
No animation so far but it goes up 242
242
and when we click, it goes down a bit, right? 243
243
So, cool. 244
244
Now all we have to do is to animate this and then 245
245
also add these shadows. 246
246
But first let's actually add the rounded corners. 247
247
So border radius, and here we can put a really high number, 248
248
like let's say even 100 pixels or something and then 249
249
what it will do is to simply shape it like this here 250
250
on the edges. 251
251
So if you put 200 or 500 pixels, 252
252
it will all still be the same, okay? 253
253
So now all we have to do is the small animation. 254
254
So remember that in the last lecture, 255
255
I said that there are two types of animations. 256
256
The first one is to simply use the transition property, 257
257
which is the easy one, and the more complex one is 258
258
the method that we used, 259
259
which was to really specify the steps of the 260
260
animations with the keyframes at-rule. 261
261
Now in this case, that's not necessary, is all. 262
262
All we have to do is use the transition property, 263
263
transition, now we have to just specify 264
264
which properties we want to animate. 265
265
And if we're not really sure, or if we don't want to 266
266
write them out, we can simply say all. 267
267
So in this case, all the properties 268
268
are enabled to be animated. 269
269
Then we can also specify a time that we want. 270
270
Let's say that we want 0.2 seconds. 271
271
So this is already the shorthand version of the transition. 272
272
So just like before here where we had a shorthand for 273
273
animation, instead of writing out all of these properties, 274
274
we do the same with transition. 275
275
We just write all of these possibilities here in the same 276
276
property as a shorthand because it's just easier. 277
277
It's another transform on the hover as well as 278
278
on the active will be animated in relation 279
279
to their initial state. 280
280
And this is actually causes sometimes a lot of confusion 281
281
as to why the transition property 282
282
has to be on the initial state. 283
283
But that's just how it works. 284
284
So on the initial states, we say that there can be 285
285
a transition basically on all the properties 286
286
and then on the hover, so here we say, how it should 287
287
look like in the hover state and in the active state 288
288
and then the animation is going to happen. 289
289
So let's take a look at that. 290
290
And yeah, here we go. 291
291
So now it moves up and very nicely it moves down, 292
292
just like this, okay. 293
293
Now all we have to do is to add the box shadow 294
294
and this also when we do the hover. 295
295
And so in the box shadow property, we can specify 296
296
a bunch of values. 297
297
So the first one is the offset in the x direction. 298
298
And since we don't want any shadow in the x direction, 299
299
you only want it in the upsilon direction, 300
300
we put a zero here. 301
301
Now in upsilon, which is the second one, we actually 302
302
want some offset, so 10 pixels let's say. 303
303
So the shadow will be 10 pixels down. 304
304
Then the third value is the blur that we want to see. 305
305
And let's say 20 pixels so we have a really high blur here. 306
306
And this makes for a more blurry shadow 307
307
so it looks like we're further away. 308
308
And so in the active box shadow, we're then 309
309
going to reduce that blur and 310
310
then it looks like we're back closer to the page, okay? 311
311
And here now, finally, we can put a color. 312
312
So an RGBA in this case because we want the color of the 313
313
shadow to be transparent. 314
314
So here we put it to black, complete black, 315
315
and then let's just put a transparency value. 316
316
So this is black, but not completely black, 317
317
but only with 20% opacity, in order to make it 318
318
just a very subtle shadow and not all too visible. 319
319
We want it to be very subtle, okay? 320
320
Now you can play around then with different numbers 321
321
to see how it's going to look like if you make it darker, 322
322
if you make it less opaque. 323
323
20% I think is a good way to go. 324
324
Now remember, when we click on the button, 325
325
so when it's active, we want the shadow to look smaller 326
326
and so to give the impression that the button is closer 327
327
to the page and so further away from the user. 328
328
So let's decrease this here to five and then we also 329
329
want it less blurred. 330
330
So let's say 10 pixels here, okay? 331
331
So I'm doing this from my experience because I have 332
332
a lot of experience by playing around with these values 333
333
so if this looks a bit like magic to you, then don't worry, 334
334
it comes with practice. 335
335
And so again, you should just play around with these numbers 336
336
and take a look how things behave 337
337
if you change the values, okay? 338
338
Now let's just take a look. 339
339
And yeah, so you see the shadow coming up, right? 340
340
And now when we click it, it goes down like this. 341
341
So we lose a bit of shadow and it also becomes less blurry. 342
342
Just to show you how it would look like with one pixel, 343
343
for example, let's see. 344
344
So you see, there's a lot less blur now, right? 345
345
But we want a little bit of blur 346
346
to make it look more natural, 347
347
and so let's put that 10 pixel that we had before. 348
348
Okay and with that we have the 349
349
first part of the button ready. 350
350
Now to build the second part of this button, 351
351
which includes some more animation effects, 352
352
just join me right in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.