Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,280 --> 00:00:04,070
So, now that you got the fundamentals
2
00:00:04,070 --> 00:00:06,060
of the box model down,
3
00:00:06,060 --> 00:00:10,040
let's go one step further and talk about different types
4
00:00:10,040 --> 00:00:13,323
of boxes that exist in the box model.
5
00:00:15,340 --> 00:00:17,310
And maybe you had already noticed
6
00:00:17,310 --> 00:00:21,880
that there are different types of boxes in CSS.
7
00:00:21,880 --> 00:00:25,483
So let's inspect this element here to show you what I mean.
8
00:00:29,674 --> 00:00:30,910
So this one, for example,
9
00:00:30,910 --> 00:00:35,600
and you see that this h2 element occupies all the space
10
00:00:35,600 --> 00:00:37,340
that it can occupy,
11
00:00:37,340 --> 00:00:40,320
so basically it goes all the way from the left side
12
00:00:40,320 --> 00:00:43,260
to the right side, right?
13
00:00:43,260 --> 00:00:47,220
And the same is true, for example, for this entire header,
14
00:00:47,220 --> 00:00:51,710
of course, for this entire article and the header as well.
15
00:00:51,710 --> 00:00:55,130
And really most of the elements are like this,
16
00:00:55,130 --> 00:00:57,410
but then there are also other elements.
17
00:00:57,410 --> 00:01:01,233
So other boxes so to say, like this one.
18
00:01:02,250 --> 00:01:04,690
So here we have this strong element,
19
00:01:04,690 --> 00:01:08,370
but you see that it only occupies exactly the space
20
00:01:08,370 --> 00:01:10,930
where its content actually is.
21
00:01:10,930 --> 00:01:13,380
And the same thing is true, for example,
22
00:01:13,380 --> 00:01:14,993
for this image here.
23
00:01:16,040 --> 00:01:19,480
So you'll see, it's only really 50x50 pixels,
24
00:01:19,480 --> 00:01:23,520
which is exactly the size of the content itself.
25
00:01:23,520 --> 00:01:28,120
And for example, the same thing here with this anchor tag,
26
00:01:28,120 --> 00:01:30,280
which again you will now see
27
00:01:30,280 --> 00:01:32,750
that it occupies exactly the width
28
00:01:32,750 --> 00:01:35,450
that is needed for its content.
29
00:01:35,450 --> 00:01:38,270
So these types of boxes that only occupied
30
00:01:38,270 --> 00:01:41,790
exactly the space that they need for its content
31
00:01:41,790 --> 00:01:44,520
is what we call inline boxes,
32
00:01:44,520 --> 00:01:47,423
and on the other hand, all these other boxes.
33
00:01:48,754 --> 00:01:53,180
So for example, this paragraph, or this h3 heading,
34
00:01:53,180 --> 00:01:58,100
these we call block-level boxes or block-level elements.
35
00:01:58,100 --> 00:02:01,030
So block-level elements or boxes
36
00:02:01,030 --> 00:02:03,780
occupy all the space that they can,
37
00:02:03,780 --> 00:02:07,390
and they basically create line breaks after them.
38
00:02:07,390 --> 00:02:08,410
Or in other words,
39
00:02:08,410 --> 00:02:12,840
they cannot be side-by-side with one another, right?
40
00:02:12,840 --> 00:02:13,770
So of course,
41
00:02:13,770 --> 00:02:16,950
if they take up all the space they need horizontally,
42
00:02:16,950 --> 00:02:20,400
then of course they cannot be side-by-side.
43
00:02:20,400 --> 00:02:22,790
That makes sense, right?
44
00:02:22,790 --> 00:02:24,950
So these are the fundamental differences
45
00:02:24,950 --> 00:02:28,500
between block-level boxes and inline boxes.
46
00:02:28,500 --> 00:02:29,870
But there are some more,
47
00:02:29,870 --> 00:02:32,333
so let's take a look at a comparison.
48
00:02:33,860 --> 00:02:37,220
So here I highlighted all of the block-level elements
49
00:02:37,220 --> 00:02:41,060
or block-level boxes that are on our page right now.
50
00:02:41,060 --> 00:02:42,980
And as I already mentioned,
51
00:02:42,980 --> 00:02:47,000
these elements are basically formatted as blocks.
52
00:02:47,000 --> 00:02:49,560
So big blocks of content,
53
00:02:49,560 --> 00:02:54,080
which occupies 100% of the parent element's width.
54
00:02:54,080 --> 00:02:57,170
And that is true even if the content itself
55
00:02:57,170 --> 00:02:59,770
wouldn't actually require so much space.
56
00:02:59,770 --> 00:03:02,980
For example, this "What is HTML" heading,
57
00:03:02,980 --> 00:03:06,550
actually it wouldn't need the entire line, right?
58
00:03:06,550 --> 00:03:09,210
But it is still a block-level element
59
00:03:09,210 --> 00:03:11,820
because then they can be stacked vertically
60
00:03:11,820 --> 00:03:14,870
one after another by default.
61
00:03:14,870 --> 00:03:17,490
Now, one thing that is very important to mention
62
00:03:17,490 --> 00:03:20,020
is that the box model applies exactly
63
00:03:20,020 --> 00:03:23,370
as I showed you before to block-level elements
64
00:03:23,370 --> 00:03:27,260
while the same is not true for inline elements,
65
00:03:27,260 --> 00:03:30,590
as we will see in a second. Okay?
66
00:03:30,590 --> 00:03:34,100
Now by default, most of the HTML elements
67
00:03:34,100 --> 00:03:36,500
are actually block-level elements,
68
00:03:36,500 --> 00:03:39,300
so things like the body, main, header,
69
00:03:39,300 --> 00:03:41,100
and so on and so forth.
70
00:03:41,100 --> 00:03:44,310
So most of the elements really that we use
71
00:03:44,310 --> 00:03:46,220
are block-level elements,
72
00:03:46,220 --> 00:03:50,630
so we can also say that they create block-level boxes.
73
00:03:50,630 --> 00:03:51,910
All right.
74
00:03:51,910 --> 00:03:55,240
Now, one thing that we can do with CSS
75
00:03:55,240 --> 00:03:59,980
is to change from inline boxes to block-level boxes.
76
00:03:59,980 --> 00:04:03,450
And we can do that with the display property set
77
00:04:03,450 --> 00:04:06,070
to the value of block,
78
00:04:06,070 --> 00:04:09,010
but we will do that in practice in a second.
79
00:04:09,010 --> 00:04:10,800
But for now, what I want to do
80
00:04:10,800 --> 00:04:14,020
is to look at the inline element
81
00:04:14,020 --> 00:04:17,063
and how it's different from block-level elements.
82
00:04:18,780 --> 00:04:23,780
So here I marked the inline elements with this red border,
83
00:04:24,450 --> 00:04:26,930
and you see that as expected,
84
00:04:26,930 --> 00:04:29,550
they only occupied exactly the space
85
00:04:29,550 --> 00:04:32,610
that is needed for its content.
86
00:04:32,610 --> 00:04:35,520
They also don't create any line breaks after
87
00:04:35,520 --> 00:04:37,320
or before the element.
88
00:04:37,320 --> 00:04:40,650
And so therefore they can simply stay inside
89
00:04:40,650 --> 00:04:44,090
of their parent elements without creating
90
00:04:44,090 --> 00:04:45,890
any additional space.
91
00:04:45,890 --> 00:04:49,840
And this is exactly what makes sense for smaller elements,
92
00:04:49,840 --> 00:04:53,640
like the strong element, the em element,
93
00:04:53,640 --> 00:04:56,130
or anchor elements, right?
94
00:04:56,130 --> 00:04:59,850
We wouldn't want these elements to create a new line
95
00:04:59,850 --> 00:05:03,040
and occupy all the width that they can.
96
00:05:03,040 --> 00:05:05,120
That just wouldn't make any sense,
97
00:05:05,120 --> 00:05:07,290
and therefore that's why we have
98
00:05:07,290 --> 00:05:09,890
these different types of boxes.
99
00:05:09,890 --> 00:05:13,940
But anyway, now about the box model, as I said,
100
00:05:13,940 --> 00:05:17,110
it works differently in inline elements.
101
00:05:17,110 --> 00:05:19,120
So for inline elements,
102
00:05:19,120 --> 00:05:23,690
the height and width properties do not have any effect.
103
00:05:23,690 --> 00:05:28,140
Also paddings and margins are only applied horizontally
104
00:05:28,140 --> 00:05:31,430
or in other words, on the left and right sides,
105
00:05:31,430 --> 00:05:34,360
but not on the top and bottom.
106
00:05:34,360 --> 00:05:35,960
And this fundamental difference
107
00:05:35,960 --> 00:05:39,260
about how the box model works for inland elements
108
00:05:39,260 --> 00:05:42,690
is extremely important to always keep in mind
109
00:05:42,690 --> 00:05:44,350
and to never forget,
110
00:05:44,350 --> 00:05:47,040
because this is a mistake that I see beginners
111
00:05:47,040 --> 00:05:49,070
make all the times,
112
00:05:49,070 --> 00:05:51,840
which is basically do not understand
113
00:05:51,840 --> 00:05:55,550
why certain properties of the box model do not work
114
00:05:55,550 --> 00:05:59,280
as expected when applied to inline elements.
115
00:05:59,280 --> 00:06:02,600
So take note of this as it is very important
116
00:06:02,600 --> 00:06:03,963
to always keep in mind.
117
00:06:04,910 --> 00:06:06,360
Now by default,
118
00:06:06,360 --> 00:06:09,520
some of the elements that are inline elements,
119
00:06:09,520 --> 00:06:13,530
so which create inline boxes are the anchor, image,
120
00:06:13,530 --> 00:06:18,500
strong, em, the button as well, and many more.
121
00:06:18,500 --> 00:06:21,660
Now, just like we can use to display property
122
00:06:21,660 --> 00:06:24,780
to make any element a block-level element,
123
00:06:24,780 --> 00:06:28,090
we can also use display set to inline
124
00:06:28,090 --> 00:06:31,000
in order to transform any block-level element
125
00:06:31,000 --> 00:06:33,180
to an inline element.
126
00:06:33,180 --> 00:06:36,220
And actually let's now go back to our code
127
00:06:36,220 --> 00:06:38,753
to see some of these things in action.
128
00:06:40,350 --> 00:06:44,460
And let's start by trying to format these links here
129
00:06:44,460 --> 00:06:45,903
that are in the header.
130
00:06:47,760 --> 00:06:52,760
So let's select them, but I will do that more down.
131
00:06:52,800 --> 00:06:55,223
Let me actually create some comments here.
132
00:06:57,220 --> 00:07:01,850
So let's say that these are like page sections
133
00:07:01,850 --> 00:07:03,303
or something like that.
134
00:07:04,300 --> 00:07:08,520
So basically all the big dividing pieces of our page.
135
00:07:08,520 --> 00:07:10,160
So we have the body, of course,
136
00:07:10,160 --> 00:07:12,540
the container, the main header,
137
00:07:12,540 --> 00:07:16,220
the navigation, article, and all of that.
138
00:07:16,220 --> 00:07:18,200
And then here is where we start to have,
139
00:07:18,200 --> 00:07:21,073
or like smaller elements.
140
00:07:22,000 --> 00:07:23,970
And these titles here don't really matter.
141
00:07:23,970 --> 00:07:26,540
I just want to have like a visual separation
142
00:07:26,540 --> 00:07:27,763
inside of the code.
143
00:07:29,750 --> 00:07:33,663
Okay, so let's go down here all the way down.
144
00:07:34,800 --> 00:07:36,870
Maybe let's see here.
145
00:07:36,870 --> 00:07:39,200
And so I want to select all the links
146
00:07:39,200 --> 00:07:42,710
that are inside of the navigation.
147
00:07:42,710 --> 00:07:47,710
So let's say navigation and then the links in there.
148
00:07:48,060 --> 00:07:48,893
And as always,
149
00:07:48,893 --> 00:07:53,003
I should use the link pseudo class to actually style them.
150
00:07:54,210 --> 00:07:57,343
Now to see this a little bit better, what happens,
151
00:07:58,940 --> 00:08:02,700
let's give them a color, a background color,
152
00:08:02,700 --> 00:08:07,693
like orange red, and now I need to manually reload here.
153
00:08:09,610 --> 00:08:13,200
Okay, so we got that background color
154
00:08:13,200 --> 00:08:16,870
and now let's start by adding some margin here,
155
00:08:16,870 --> 00:08:21,150
just so we see that the box model does in fact,
156
00:08:21,150 --> 00:08:23,683
not applied way that we thought it would.
157
00:08:24,530 --> 00:08:28,023
So let's say 20 pixels and give it a save.
158
00:08:28,860 --> 00:08:33,200
And you see that some margin was edit horizontally.
159
00:08:33,200 --> 00:08:36,790
So on the left and right side, right.
160
00:08:36,790 --> 00:08:41,790
But what did not happen was that vertical space was created.
161
00:08:42,260 --> 00:08:45,633
So the top and bottom margins remained unchanged.
162
00:08:47,050 --> 00:08:50,980
Now, if we check this out here in the box model,
163
00:08:50,980 --> 00:08:54,763
in the dev tools, then it will still appear down here,
164
00:08:56,900 --> 00:08:58,900
some more space here.
165
00:08:58,900 --> 00:09:01,840
So you see that the 20 value does still appear,
166
00:09:01,840 --> 00:09:04,573
but then here on the colored overlay,
167
00:09:05,760 --> 00:09:09,750
so here this orange, actually did not create any space,
168
00:09:09,750 --> 00:09:12,840
even though it says 20 here, right?
169
00:09:12,840 --> 00:09:14,720
And so, as you know by now,
170
00:09:14,720 --> 00:09:17,650
the reason for that is that the anchor element
171
00:09:17,650 --> 00:09:20,470
is an inline element where the box model
172
00:09:20,470 --> 00:09:23,340
does not create any vertical space,
173
00:09:23,340 --> 00:09:25,883
and the same is true for padding.
174
00:09:28,820 --> 00:09:30,753
So padding of 20 pixels.
175
00:09:33,137 --> 00:09:34,700
So let's see.
176
00:09:34,700 --> 00:09:39,480
And now it does actually look as if some space was created,
177
00:09:39,480 --> 00:09:43,570
but that is only true for inside of the element
178
00:09:43,570 --> 00:09:47,410
because in fact, the anchor content,
179
00:09:47,410 --> 00:09:50,100
so the anchor content itself is still
180
00:09:50,100 --> 00:09:52,030
in the exact same place,
181
00:09:52,030 --> 00:09:54,570
but if this was a block-level element,
182
00:09:54,570 --> 00:09:58,000
then all of this would have moved down a little bit.
183
00:09:58,000 --> 00:10:00,570
So basically the fill area of this element
184
00:10:00,570 --> 00:10:04,460
has been expanded and filled with the background color,
185
00:10:04,460 --> 00:10:07,553
but no new space was in fact created.
186
00:10:08,700 --> 00:10:10,250
Okay?
187
00:10:10,250 --> 00:10:13,130
But if we actually want to have that space,
188
00:10:13,130 --> 00:10:17,390
and if we want the elements to be one after another,
189
00:10:17,390 --> 00:10:21,393
then of course we can change them to block-level elements.
190
00:10:22,470 --> 00:10:25,860
So that is exactly what I showed you in the slide
191
00:10:25,860 --> 00:10:28,880
by using the display property
192
00:10:28,880 --> 00:10:31,960
and set it to the value of block.
193
00:10:31,960 --> 00:10:34,520
So this will then render the inline element
194
00:10:34,520 --> 00:10:36,033
as a block-level element.
195
00:10:36,960 --> 00:10:38,660
So what do you think will happen
196
00:10:38,660 --> 00:10:40,183
once I save this now?
197
00:10:41,300 --> 00:10:43,220
And there we go,
198
00:10:43,220 --> 00:10:48,050
now all of these elements occupy all the width that they can
199
00:10:48,050 --> 00:10:50,050
and also they have now actually
200
00:10:50,050 --> 00:10:53,060
also vertical margins between them.
201
00:10:53,060 --> 00:10:58,060
Now they are kind of outside of this header element now
202
00:10:58,220 --> 00:11:02,630
because we set the header element to a fixed height,
203
00:11:02,630 --> 00:11:05,080
so in one of the previous lectures.
204
00:11:05,080 --> 00:11:08,073
So let me show that to you with the overlay.
205
00:11:10,470 --> 00:11:12,540
We need some more space here.
206
00:11:12,540 --> 00:11:15,890
And so since we set the height to the header
207
00:11:15,890 --> 00:11:19,240
to a specific value of 80 pixels,
208
00:11:19,240 --> 00:11:21,730
then the content no longer fits in there,
209
00:11:21,730 --> 00:11:24,340
and so the element did not expand
210
00:11:24,340 --> 00:11:26,540
in order to fit the content.
211
00:11:26,540 --> 00:11:28,150
So that's the reason why usually
212
00:11:28,150 --> 00:11:32,230
we don't set a fixed height on elements.
213
00:11:32,230 --> 00:11:33,973
So let me go back and change that,
214
00:11:35,710 --> 00:11:37,963
so that was just a demo anyway.
215
00:11:39,100 --> 00:11:43,040
So yeah, here is the height that we set to 80.
216
00:11:43,040 --> 00:11:46,433
So let me comment that out, save it again.
217
00:11:46,433 --> 00:11:48,800
Now the element expanded vertically here
218
00:11:48,800 --> 00:11:53,130
to account for the additional space that is required.
219
00:11:53,130 --> 00:11:56,130
Okay. So hopefully that makes sense.
220
00:11:56,130 --> 00:12:00,760
But the main point here is that these anchor elements here
221
00:12:00,760 --> 00:12:02,880
now do satisfy all the conditions
222
00:12:02,880 --> 00:12:05,400
of being a block-level element.
223
00:12:05,400 --> 00:12:08,370
So the box model applies to them normally,
224
00:12:08,370 --> 00:12:12,370
and they occupy 100% of the available width,
225
00:12:12,370 --> 00:12:15,740
and so therefore they appear one after another
226
00:12:15,740 --> 00:12:17,903
nicely formatted as blocks.
227
00:12:19,620 --> 00:12:21,010
All right.
228
00:12:21,010 --> 00:12:24,050
So they occupy all the space as we see here,
229
00:12:24,050 --> 00:12:26,790
which of course includes the margin.
230
00:12:26,790 --> 00:12:31,790
So each of these, if we take a look has some margin, right?
231
00:12:31,900 --> 00:12:36,160
So that is this kind of orange color here.
232
00:12:36,160 --> 00:12:38,770
And so that is part of the entire space
233
00:12:38,770 --> 00:12:43,440
that the element itself requires, all right?
234
00:12:43,440 --> 00:12:45,280
Well, let's go back down here
235
00:12:45,280 --> 00:12:47,390
and actually turn all of this off
236
00:12:48,310 --> 00:12:52,040
because this was really just a demo.
237
00:12:52,040 --> 00:12:54,010
Okay? And now of course,
238
00:12:54,010 --> 00:12:56,800
we will see the header shrink back
239
00:12:56,800 --> 00:13:00,393
to only occupy vertically here the space that it needs.
240
00:13:01,242 --> 00:13:03,690
All right, so as we keep adding more and more elements,
241
00:13:03,690 --> 00:13:05,350
then this should grow,
242
00:13:05,350 --> 00:13:07,390
which is exactly what's happened before
243
00:13:07,390 --> 00:13:09,270
when these links were bigger,
244
00:13:09,270 --> 00:13:11,350
but now they're back to being small
245
00:13:11,350 --> 00:13:15,550
and therefore all that space we had was not required.
246
00:13:15,550 --> 00:13:20,040
And now next, let's actually quickly try the opposite
247
00:13:20,040 --> 00:13:24,963
and change some block-level elements to inline elements.
248
00:13:25,920 --> 00:13:27,400
So for example,
249
00:13:27,400 --> 00:13:28,660
let's try what happens
250
00:13:28,660 --> 00:13:33,260
when we make the list elements as inline.
251
00:13:33,260 --> 00:13:35,773
Display, inline.
252
00:13:39,260 --> 00:13:40,883
Let's remove this actually.
253
00:13:41,760 --> 00:13:45,870
And now you'll see that these three elements
254
00:13:45,870 --> 00:13:48,450
are now basically side-by-side
255
00:13:48,450 --> 00:13:50,853
and occupy only the space that they need.
256
00:13:51,920 --> 00:13:53,830
And actually let's bring this back
257
00:13:53,830 --> 00:13:55,820
because as I mentioned,
258
00:13:55,820 --> 00:13:58,070
the dev tools are really so important
259
00:13:58,070 --> 00:14:03,070
especially for overlaying like these boxes, right?
260
00:14:04,910 --> 00:14:07,960
So now the boxes are side-by-side like this
261
00:14:07,960 --> 00:14:10,420
because they are inline boxes.
262
00:14:10,420 --> 00:14:13,470
So they no longer create the line breaks after them
263
00:14:13,470 --> 00:14:17,010
and only occupied a space that they need.
264
00:14:17,010 --> 00:14:18,163
Let's try the same.
265
00:14:19,220 --> 00:14:22,533
I'll turn it off here and try the same on the paragraphs.
266
00:14:28,420 --> 00:14:32,190
And so that looks even stranger
267
00:14:32,190 --> 00:14:34,550
because all the texts basically collapsed
268
00:14:34,550 --> 00:14:39,550
just into one big line of text, it looks like, right?
269
00:14:45,524 --> 00:14:47,360
So again, each of these elements now
270
00:14:47,360 --> 00:14:50,563
basically only occupies the space that it needs.
271
00:14:52,600 --> 00:14:54,930
All right, but let's remove this
272
00:14:54,930 --> 00:14:58,090
because it doesn't make much sense in the situation,
273
00:14:58,090 --> 00:15:02,390
but at some situations it actually makes a lot of sense.
274
00:15:02,390 --> 00:15:03,960
Now, in many situations,
275
00:15:03,960 --> 00:15:07,010
what makes even more sense is to transform
276
00:15:07,010 --> 00:15:09,840
a block-level element into something called
277
00:15:09,840 --> 00:15:12,490
an inline-block element.
278
00:15:12,490 --> 00:15:16,900
So basically that's a mix of inline and block-level.
279
00:15:16,900 --> 00:15:19,733
So let's quickly check out what that means.
280
00:15:21,520 --> 00:15:24,940
So here, we have a quick summary of both the block-level
281
00:15:24,940 --> 00:15:26,640
and the inline boxes.
282
00:15:26,640 --> 00:15:28,060
So we already know that,
283
00:15:28,060 --> 00:15:31,200
so we don't need to go over all that again.
284
00:15:31,200 --> 00:15:34,400
But then there's basically a third type of box,
285
00:15:34,400 --> 00:15:36,860
which is a mix between these two.
286
00:15:36,860 --> 00:15:41,860
And so that is, as I said before, the inline-block box.
287
00:15:42,000 --> 00:15:44,300
So inline-block boxes,
288
00:15:44,300 --> 00:15:47,930
they look like inlines from the outside,
289
00:15:47,930 --> 00:15:52,930
but they behave like block-level elements on the inside.
290
00:15:52,930 --> 00:15:56,680
So what that means is that inline-block boxes
291
00:15:56,680 --> 00:16:00,970
do only occupied the space that they need for the content,
292
00:16:00,970 --> 00:16:05,130
and so therefore they do not cause any line breaks.
293
00:16:05,130 --> 00:16:09,120
So this is what I mean when I say that the inline-block box
294
00:16:09,120 --> 00:16:13,380
behaves like an inline box from the outside.
295
00:16:13,380 --> 00:16:14,970
However, as I said,
296
00:16:14,970 --> 00:16:18,920
it behaves like a block-level box on the inside,
297
00:16:18,920 --> 00:16:22,580
and so what that means is that the box model applies
298
00:16:22,580 --> 00:16:26,240
just as it does for block-level boxes.
299
00:16:26,240 --> 00:16:29,130
So we can still set heights and width,
300
00:16:29,130 --> 00:16:32,290
and we can still use margins and paddings
301
00:16:32,290 --> 00:16:36,700
just like on block-level boxes or on block-level elements.
302
00:16:36,700 --> 00:16:38,410
So these are kind of the same,
303
00:16:38,410 --> 00:16:42,080
so I keep using them interchangeably.
304
00:16:42,080 --> 00:16:46,230
So essentially, inline-block boxes really combines
305
00:16:46,230 --> 00:16:50,250
the best of both worlds of block-level and inline.
306
00:16:50,250 --> 00:16:53,360
And in order to create an inline-block element,
307
00:16:53,360 --> 00:16:56,970
all we have to do is to set the display property
308
00:16:56,970 --> 00:17:00,030
to inline-block and that's it.
309
00:17:00,030 --> 00:17:03,040
And so let's now see how we do that in practice
310
00:17:03,040 --> 00:17:06,803
and some situations where this can be extremely helpful.
311
00:17:08,270 --> 00:17:11,790
So let's go back here to our header links.
312
00:17:11,790 --> 00:17:13,550
So to this navigation,
313
00:17:13,550 --> 00:17:16,770
so that I can show you where an inline-block element
314
00:17:16,770 --> 00:17:18,700
can be very helpful.
315
00:17:18,700 --> 00:17:22,670
So right now there is another lot of formatting here,
316
00:17:22,670 --> 00:17:25,973
so like no spacing, so we need to fix that.
317
00:17:27,630 --> 00:17:32,270
So this was somewhere down here, right here.
318
00:17:32,270 --> 00:17:36,070
And so let's go back to trying to add some margins
319
00:17:37,070 --> 00:17:41,313
without changing anything in the display property for now.
320
00:17:42,660 --> 00:17:47,450
So let's say we wanted a margin of 30 pixels,
321
00:17:47,450 --> 00:17:51,090
and this should work because this is a horizontal space,
322
00:17:51,090 --> 00:17:54,400
and so that works even on inline elements.
323
00:17:54,400 --> 00:17:56,950
But now if I wanted to add a margin top
324
00:17:59,650 --> 00:18:04,650
of let's say 10 pixels, then nothing will change, right?
325
00:18:05,360 --> 00:18:08,690
So it's stays the same and that's exactly the behavior
326
00:18:08,690 --> 00:18:11,290
that we saw already at the beginning.
327
00:18:11,290 --> 00:18:15,883
But now if we change the display to inline-block,
328
00:18:16,930 --> 00:18:18,673
then see what happens.
329
00:18:20,000 --> 00:18:24,400
So you saw that now we got our space here.
330
00:18:24,400 --> 00:18:25,813
And if we check this out,
331
00:18:26,870 --> 00:18:31,660
then indeed you can see that orange space on the right side
332
00:18:31,660 --> 00:18:34,780
and then the 10 pixels on the top.
333
00:18:34,780 --> 00:18:37,840
So the box model is back to being applied
334
00:18:37,840 --> 00:18:40,070
as a block-level element,
335
00:18:40,070 --> 00:18:43,400
but on the outside the elements are still side-by-side
336
00:18:43,400 --> 00:18:46,300
and occupying only the space they need,
337
00:18:46,300 --> 00:18:48,563
so behaving like inline elements.
338
00:18:49,550 --> 00:18:52,640
So this is a great technique in some situations,
339
00:18:52,640 --> 00:18:53,980
even though at this point,
340
00:18:53,980 --> 00:18:57,840
we also have more modern ways of doing something similar,
341
00:18:57,840 --> 00:19:01,870
but in some cases this will actually be very good to know,
342
00:19:01,870 --> 00:19:05,720
and a good technique to have in your tool belt.
343
00:19:05,720 --> 00:19:07,320
Now just one final detail
344
00:19:07,320 --> 00:19:09,910
is that we should remove that margin right
345
00:19:09,910 --> 00:19:12,010
from the last element.
346
00:19:12,010 --> 00:19:13,240
So let's select that
347
00:19:14,680 --> 00:19:18,350
nav a link,
348
00:19:18,350 --> 00:19:20,770
and now you will see something new.
349
00:19:20,770 --> 00:19:24,010
So this here is a pseudo class, right.
350
00:19:24,010 --> 00:19:27,410
But on to that we can chain another pseudo class
351
00:19:27,410 --> 00:19:31,093
because now we want the last-child, right.
352
00:19:32,150 --> 00:19:35,830
Like this, and then we want to set the margin
353
00:19:37,808 --> 00:19:42,170
right back to zero, okay.
354
00:19:42,170 --> 00:19:43,810
So visually that changes nothing,
355
00:19:43,810 --> 00:19:47,630
but here we now see that this one no longer has dead space
356
00:19:47,630 --> 00:19:51,460
on the right side and many times that's important to do.
357
00:19:51,460 --> 00:19:54,620
And so that's why I wanted to show you that we can chain
358
00:19:54,620 --> 00:19:58,340
these to pseudo classes like this without any problem.
359
00:19:58,340 --> 00:20:01,140
Great, and now just to finish,
360
00:20:01,140 --> 00:20:03,430
I wanted to show you that images
361
00:20:03,430 --> 00:20:06,880
are actually inline-block boxes.
362
00:20:06,880 --> 00:20:07,920
All right.
363
00:20:07,920 --> 00:20:10,040
So I said in the beginning that images
364
00:20:10,040 --> 00:20:13,340
are actually inline elements, but in fact,
365
00:20:13,340 --> 00:20:16,960
they do behave like inline-block elements
366
00:20:16,960 --> 00:20:21,030
and we can easily demonstrate this by adding some margin,
367
00:20:21,030 --> 00:20:25,000
for example, to this post image here.
368
00:20:25,000 --> 00:20:29,950
So if I add a margin of a 100 pixels here,
369
00:20:29,950 --> 00:20:32,450
then if it was an inline element,
370
00:20:32,450 --> 00:20:35,530
it should not create any vertical space.
371
00:20:35,530 --> 00:20:39,310
So not here and not here. All right.
372
00:20:39,310 --> 00:20:41,643
But watch what happens as I save this.
373
00:20:42,900 --> 00:20:44,650
And so indeed you see
374
00:20:44,650 --> 00:20:47,603
that all of this vertical space here was added.
375
00:20:48,460 --> 00:20:51,130
And so that is proof that indeed
376
00:20:51,130 --> 00:20:53,850
it is an inline-block element
377
00:20:53,850 --> 00:20:55,910
and the same is true for the fact
378
00:20:55,910 --> 00:20:59,610
that we can set width and heights for this element.
379
00:20:59,610 --> 00:21:02,440
So if it was a purely inline element,
380
00:21:02,440 --> 00:21:06,053
then these two here would also not work, right.
381
00:21:07,200 --> 00:21:09,900
So that's also important to note
382
00:21:09,900 --> 00:21:12,633
and let's just set it back to normal here.
383
00:21:13,480 --> 00:21:18,480
Okay. So that's it for the type of boxes in CSS.
384
00:21:18,860 --> 00:21:20,410
Just as a quick summary
385
00:21:20,410 --> 00:21:24,120
or basically as a takeaway from this lecture,
386
00:21:24,120 --> 00:21:26,540
most of the time we will actually leave
387
00:21:26,540 --> 00:21:28,450
the display setting alone
388
00:21:28,450 --> 00:21:31,630
and simply use the predefined box type
389
00:21:31,630 --> 00:21:35,470
because by default, they do actually make a lot of sense.
390
00:21:35,470 --> 00:21:38,770
However, we can use display set to block
391
00:21:38,770 --> 00:21:41,410
in order to make a small inline element,
392
00:21:41,410 --> 00:21:44,470
for example, occupy an entire line,
393
00:21:44,470 --> 00:21:47,220
which is something that we will sometimes need
394
00:21:47,220 --> 00:21:48,870
in the real world.
395
00:21:48,870 --> 00:21:50,410
Then the other way around,
396
00:21:50,410 --> 00:21:53,560
sometimes we don't want a block-level element
397
00:21:53,560 --> 00:21:57,230
to push all the other elements into a new line.
398
00:21:57,230 --> 00:22:00,020
So basically we don't always want them to occupy
399
00:22:00,020 --> 00:22:03,750
all the available blank space that there is to fill.
400
00:22:03,750 --> 00:22:05,330
And so in that case,
401
00:22:05,330 --> 00:22:07,930
we can set them to an inline element
402
00:22:07,930 --> 00:22:10,350
or probably even more useful,
403
00:22:10,350 --> 00:22:12,960
we can set them to an inline-block element
404
00:22:12,960 --> 00:22:16,973
because then we can still apply the box model as usual.
30371
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.