为什么会有 margin 塌陷问题?

为什么会有margin塌陷问题,好奇怪的东西,一开始以为只有margin-top的塌陷,原来margin-bottom也不行!!!!好郁闷

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .container {
      background-color: yellow;
    }

    .one {
      width: 100px;
      height: 100px;
      background-color: pink;
      margin-top: 20px;
      margin-bottom: 20px;
    }

    .two {
      width: 100px;
      height: 100px;
      background-color: skyblue;
      margin-top: 40px;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="one">one</div>
  </div>
  <div class="container">
    <div class="two">two</div>
  </div>
</body>

</html>
阅读 1.7k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题