html - CSS 定位 : Content that should be below the fold is appearing above the fold

标签 html css css-position

我正在尝试构建一个分为首屏和非首屏部分的页面,让查看者有一种进入海底的印象。我遇到了一个绊脚石,因为当涉及到 CSS 定位的概念时,我的脑子里有些东西就是拒绝点击。

最终,我试图在折叠下方添加另一个部分,我可以在其中添加内容,但希望上面的水场景保持全宽。目前,我想要显示在首屏下方的内容正在首屏部分呈现。

body {
  background: #90caf9;
}

.above-water {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
}

.wave {
  position: absolute;
  width: 100%;
  height: 220px;
  bottom: 0;
  left: 0;
  background: radial-gradient(circle farthest-corner at 50% 0%, transparent 30%, #2179ea 30%, #2179ea 45%, #1d86ea 45%, #1d86ea 60%, #2a9eea 60%, #2a9eea 75%, #02b0ea 75%);
  -webkit-animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
  -moz-animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
  animation: anim-h-wave 4s linear infinite, anim-v-wave 2s infinite alternate;
}

.container {
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

@-webkit-keyframes anim-h-wave {
  0% {
    background-position: -100px 0;
  }
  100% {
    background-position: 100px 0;
  }
}

@keyframes anim-h-wave {
  0% {
    background-position: -100px 0;
  }
  100% {
    background-position: 100px 0;
  }
}

@-webkit-keyframes anim-v-wave {
  0% {
    background-size: 100px 220px;
  }
  100% {
    background-size: 100px 270px;
  }
}

@keyframes anim-v-wave {
  0% {
    background-size: 100px 220px;
  }
  100% {
    background-size: 100px 270px;
  }
}
<section id="above-the-water">
  <div class="above-water">
    <div class="wave"></div>
  </div>
</section>

<section id="underwater">
  <div class="container">
    <h1>test</h1>
  </div>
</section>

如果需要,可以在我的笔上找到完整代码 https://codepen.io/sabey-dc/pen/zYOdNOv

最佳答案

您必须将 margin-top: 100vh 添加到水下部分,因为由于上面的水具有绝对定位,它不会自行将水下内容向下推。

关于html - CSS 定位 : Content that should be below the fold is appearing above the fold,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57731739/

相关文章:

html - 处理许多相似的 div 标签

css - 带 CSS 的箭头边框

firefox - 绝对定位在 Chrome 和 IE 中工作正常,但在 FF 中不行

html - 将元素固定到容器底部

html - 无法在 Scrapy 中使用 XPath 访问 HTML 元素

html - 是否可以将 div 与另一个不会影响居中的元素居中?

javascript - 在 302 重定向或嵌入/对象/iframe 标记内的元素(跨域)后获取 flash src

html - html 表格的最大和最小宽度在 CSS 中不起作用

javascript - 为什么滑动效果后div内容跳转

html - 使 Bootstrap 列内容固定位置