Skip to content

Commit 3603109

Browse files
committed
The bigger margin effect 🍓
1 parent cda925e commit 3603109

File tree

1 file changed

+69
-0
lines changed
  • 29-margin-collapse-101/03-rules-of-margin-collapse/04-the-bigger-margin-wins

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>CSS - Margin Collapse 101</title>
7+
<link href="https://fonts.cdnfonts.com/css/wotfard" rel="stylesheet" />
8+
<style>
9+
*,
10+
*::before,
11+
*::after {
12+
margin: 0;
13+
padding: 0;
14+
box-sizing: border-box;
15+
line-height: 1.5;
16+
}
17+
18+
body {
19+
font-family: "wotfard", sans-serif;
20+
background-color: black;
21+
}
22+
23+
.container {
24+
width: fit-content;
25+
margin-left: auto;
26+
margin-right: auto;
27+
}
28+
29+
h2 {
30+
color: white;
31+
text-align: center;
32+
margin: 20px 0;
33+
}
34+
35+
.box {
36+
width: 600px;
37+
height: 300px;
38+
display: flex;
39+
background-color: white;
40+
align-items: center;
41+
justify-content: center;
42+
border-radius: 4px;
43+
margin-left: auto;
44+
margin-right: auto;
45+
}
46+
47+
/*
48+
What about when the margins are asymmetrical? Say, the top element wants 60px of space below, while the bottom element only needs 40px?
49+
50+
The bigger number wins. So the overall margin is 60px.
51+
*/
52+
53+
.paragraph-1 {
54+
margin-bottom: 60px;
55+
}
56+
57+
.paragraph-2 {
58+
margin-top: 40px;
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<div class="container">
64+
<h2>Margin collapse 101 - The bigger margin wins</h2>
65+
<p class="box paragraph-1">Paragraph 1</p>
66+
<p class="box paragraph-2">Paragraph 2</p>
67+
</div>
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)