1
00:00:02,070 --> 00:00:03,420
Inline block elements,

2
00:00:03,420 --> 00:00:05,433
have another special behavior, though.

3
00:00:06,689 --> 00:00:09,963
If you look at our "H1" element here, this one,

4
00:00:11,580 --> 00:00:14,590
you'll see that we have a margin of 12 pixels,

5
00:00:14,590 --> 00:00:16,062
you can see it down here.

6
00:00:17,420 --> 00:00:20,227
If we go back to our code, to the description

7
00:00:20,227 --> 00:00:23,800
and add a margin of maybe 24 pixels here,

8
00:00:23,800 --> 00:00:28,650
a bigger one, if we do that, What's happening here?

9
00:00:28,650 --> 00:00:32,630
Well, we have a margin of 12 pixels here actually

10
00:00:32,630 --> 00:00:35,110
for our "H1" element. And for the paragraph,

11
00:00:35,110 --> 00:00:37,373
we have the margin of 24 pixels.

12
00:00:38,580 --> 00:00:42,310
But if you look at the margin that is used in the end,

13
00:00:42,310 --> 00:00:43,233
Can you see it?

14
00:00:44,840 --> 00:00:49,770
Here, this margin ends slightly below the "G" of "Upcoming",

15
00:00:49,770 --> 00:00:52,150
sort to say, and this margin here,

16
00:00:52,150 --> 00:00:53,787
begins below that "G".

17
00:00:54,660 --> 00:00:56,090
what that simply means, is that the margin

18
00:00:56,090 --> 00:00:57,700
in between these two elements,

19
00:00:57,700 --> 00:00:59,710
is simply 24 pixels.

20
00:00:59,710 --> 00:01:02,900
So the 12 pixels here for our bottom margin

21
00:01:02,900 --> 00:01:05,173
for the "H1" element is simply ignored.

22
00:01:06,440 --> 00:01:09,370
If I will change the margin here to 8 pixels

23
00:01:09,370 --> 00:01:11,250
for our description,

24
00:01:11,250 --> 00:01:12,083
like this,

25
00:01:12,083 --> 00:01:13,850
then it would be different.

26
00:01:13,850 --> 00:01:17,862
Here, We now see that the bottom margin here,

27
00:01:17,862 --> 00:01:22,490
ends with the content of our paragraph,

28
00:01:22,490 --> 00:01:24,040
and the margin of the paragraph

29
00:01:24,040 --> 00:01:27,060
is also part of this margin. Can you see it?

30
00:01:27,060 --> 00:01:28,840
So, the margin between these two elements,

31
00:01:28,840 --> 00:01:31,563
is now defined by this 12 pixel margin.

32
00:01:32,730 --> 00:01:34,380
So, these are two block elements

33
00:01:34,380 --> 00:01:37,320
where this is happening, here for the paragraph,

34
00:01:37,320 --> 00:01:40,780
we again have our 8 pixel margin,

35
00:01:40,780 --> 00:01:44,700
but here; the 12 pixels for the anchor tag, some are added.

36
00:01:44,700 --> 00:01:48,853
So we have 8 pixels, and then we have 12 pixels.

37
00:01:49,730 --> 00:01:53,580
So the distance between these two elements is 20 pixels.

38
00:01:53,580 --> 00:01:55,700
Here the distance, is 12 pixels,

39
00:01:55,700 --> 00:01:58,723
defined by the "H1", not 20 pixels.

40
00:02:00,060 --> 00:02:01,798
The behavior we see here between

41
00:02:01,798 --> 00:02:04,900
our adjacent elements, it's important.

42
00:02:04,900 --> 00:02:08,940
This only happens between adjacent elements,

43
00:02:08,940 --> 00:02:12,070
this is called margin collapsing,

44
00:02:12,070 --> 00:02:15,510
because well, margins collapse here in a way

45
00:02:15,510 --> 00:02:19,870
that we define a margin for the "H1" element,

46
00:02:19,870 --> 00:02:22,660
here, for example; the 12 pixels,

47
00:02:22,660 --> 00:02:24,350
and for the following paragraph.

48
00:02:24,350 --> 00:02:27,810
But we define the margin of 8 pixels.

49
00:02:27,810 --> 00:02:28,968
In such cases, well...

50
00:02:28,968 --> 00:02:33,050
The larger margin wins. Sort to say.

51
00:02:33,050 --> 00:02:37,120
Margin collapsing only occurs for vertical margins.

52
00:02:37,120 --> 00:02:40,860
So for horizontal margins, we don't have this issue,

53
00:02:40,860 --> 00:02:43,419
and only happens for block elements.

54
00:02:43,419 --> 00:02:44,989
Why is this the case?

55
00:02:44,989 --> 00:02:47,290
Well, because for inline elements,

56
00:02:47,290 --> 00:02:49,540
we cannot apply vertical margins.

57
00:02:49,540 --> 00:02:51,670
We talked about this already,

58
00:02:51,670 --> 00:02:53,259
and for inline block elements.

59
00:02:53,259 --> 00:02:57,020
So elements with the display inline block rule applied,

60
00:02:57,020 --> 00:03:00,520
well, margin collapsing, simply isn't an issue.

61
00:03:00,520 --> 00:03:03,360
You'll see it here between the paragraph and the anchor tag,

62
00:03:03,360 --> 00:03:07,650
which has the display inline block rule applied,

63
00:03:07,650 --> 00:03:09,750
the margin collapsing is not the case.

64
00:03:09,750 --> 00:03:12,160
So here we have the distance of 8 pixels

65
00:03:12,160 --> 00:03:14,560
for the bottom margin, and additionally,

66
00:03:14,560 --> 00:03:17,280
we have 12 pixels for the top margin

67
00:03:17,280 --> 00:03:19,133
for our anchor tag here.

68
00:03:20,270 --> 00:03:23,950
Now, why is margin collapsing existing?

69
00:03:23,950 --> 00:03:25,590
Well, I think it becomes evident

70
00:03:25,590 --> 00:03:27,880
if we look at our main section

71
00:03:27,880 --> 00:03:31,230
here and look into our order list,.

72
00:03:31,230 --> 00:03:33,262
Because here, between our list items,

73
00:03:33,262 --> 00:03:35,730
we have the same logic.

74
00:03:35,730 --> 00:03:40,130
We have a margin of 32 pixels top and bottom,

75
00:03:40,130 --> 00:03:41,300
as can be seen here.

76
00:03:41,300 --> 00:03:43,490
And as you see already in the left part,

77
00:03:43,490 --> 00:03:45,557
in our DevTools, if we use these,

78
00:03:45,557 --> 00:03:48,280
we only have the 32 pixel margin

79
00:03:48,280 --> 00:03:51,170
between each single list item.

80
00:03:51,170 --> 00:03:53,270
Although, each list item itself,

81
00:03:53,270 --> 00:03:56,630
has a margin of 32 pixels applied,

82
00:03:56,630 --> 00:03:58,003
as can be seen right here.

83
00:03:59,150 --> 00:04:00,700
If you think about that a bit more,

84
00:04:00,700 --> 00:04:03,820
it makes sense that this margin collapsing happens here.

85
00:04:03,820 --> 00:04:06,430
Because if you add a margin of 42 pixels,

86
00:04:06,430 --> 00:04:09,910
you probably want to have a distance of this 42 pixels

87
00:04:09,910 --> 00:04:13,283
between your elements and not 64 pixels.

88
00:04:13,283 --> 00:04:15,843
This will simply be too big, for example.

89
00:04:16,820 --> 00:04:19,010
So, these are actually all the basics

90
00:04:19,010 --> 00:04:20,269
you have to keep in mind

91
00:04:20,269 --> 00:04:22,740
when it comes to margin collapsing.

92
00:04:22,740 --> 00:04:24,930
It happens between adjacent elements,

93
00:04:24,930 --> 00:04:27,200
it only affects vertical margins,

94
00:04:27,200 --> 00:04:29,800
and therefore, it kind of simply defines

95
00:04:29,800 --> 00:04:31,710
that the bigger margin defined

96
00:04:31,710 --> 00:04:32,543
between two following elements wins,

97
00:04:32,543 --> 00:04:36,420
in such cases when it comes

98
00:04:36,420 --> 00:04:38,060
to defining the distance,

99
00:04:38,060 --> 00:04:40,763
the margin between these two elements.

