marginの相殺について


★FlexBoxではmarginの相殺が起きない★
(ドットインストール 「詳解CSS フレックスボックス編 #11 縦方向に要素を配置してみよう」)

HTML

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSSの練習</title>
  <link rel="stylesheet" href="css/styles.css">
</head>
<body>
  <header>Header</header>
  <div class="container">
    <main>Main</main>
    <nav>Nav</nav>
    <aside>Aside</aside>
  </div>
</body>
</html>

CSS

html {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100%
}

header {
  background: pink;
  margin-bottom: 100px;
}

.container {
  display: flex;
  flex: 1;
  margin-top: 50px;
}

main {
  background: skyblue;
  flex: 1;
}

nav {
  background: tomato;
  width: 100px;
  order: -1;
}

aside {
  background: orange;
  width: 100px;
}

footer {
  background: silver;
}

上のように

header {
background: pink;
margin-bottom: 100px;
}

.container {
display: flex;
flex: 1;
margin-top: 50px;
}

だとmarginが打ち消されてmargin-bottom:100pxだけが適用されそうだが、
FlexBoxなので両方適用されて150pxとなる。