css::after 伪类之后的元素重叠 div

Elements after css::after pseudoclass are overlaping div

我试图重塑我的 div 在 div 之后使用 ::after 伪类添加一些额外的形状, 所以看起来像这样:

CODESANDBOX:https://codesandbox.io/s/epic-goldstine-gdueg?file=/index.html

为什么这个 div::after 之后的 h2 标签重叠 div,为什么它不在这个紫色元素下面。我怎样才能做到这一点:

我不想在这个伪类之后为 h2 标签添加边距。 Ty 所有解决方案!

发生这种情况是因为您已将 div 高度限制为 400px 为父级设置更多高度,这样您就可以避免该问题。

* {
  margin: 0;
  padding: 0;
}
.container {
  height: 100%;
}

.dv {
  width: 100%;
  height: 400px;
  background-color: #25aaa0;
  position: relative;
  display: block;
}

.dv::after {
  content: "";
  display: block;
  position: absolute;
  top: calc(100% - 405px);
  width: 100%;
  height: 500px;
  /* background-color: #25aaa0; */
  background-color: blueviolet;
  clip-path: ellipse(65% 50% at 50% 50%);
  z-index: -1;
}
/*400px is the height of the div .dv and 85px is the height of the pseudo element's height 500px - cut off height on top:405px */
.container {height: calc(400px + 85px);}
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
    <link rel="stylesheet" href="./index.css" />
  </head>
  <body>
    <div class="container">
      <div class="dv">
        <h2>Test</h2>
      </div>
    </div>
    <h2>Test</h2>
  </body>
</html>