html - 部分绝对位于彼此之上

标签 html css

我有部分包裹在 div 中。我希望每个部分都是窗口的高度并且一个接一个地坐在页面上,我已经在 div 中实现了这一点。但目前流程 div 位于文章 div 上,我希望流程 div 继续相同的流程,以便在文章 div 的最后一部分之后我们看到流程 div 的第一部分。

这是 HTML:

    .window {
      width: 100%;
      height: 100%;
      position: absolute;
    }
    
    .window:nth-child(1) {
      top: 0%;
    }
    
    .window:nth-child(2) {
      top: 100%;
    }
    
    .window:nth-child(3) {
      top: 200%;
    }
<div class="articles">
         <section class="window">
         </section>
         <section class="window">
         </section>
    </div>
    <div class="process">
         <section class="window">
         </section>
         <section class="window">
         </section>
         <section class="window">
         </section>
    </div>

最佳答案

你正在使用 position: absolute 即为什么它表现得很奇怪,而不是像下面的代码片段那样改变你的 CSS

此处 vh 是 vh:1/100th viewport height窗口高度的百分比。

代码片段

.window {
  width: 100%;
  height: 100vh;
  position: relative;
}

.window:nth-child(1) {
  background: red;
}

.window:nth-child(2) {
  background: green;
}

.window:nth-child(3) {
  background: blue;
}
<div class="articles">
  <section class="window">articles 1
  </section>
  <section class="window">articles 2
  </section>
</div>
<div class="process">
  <section class="window">process 1
  </section>
  <section class="window">process 2
  </section>
  <section class="window">process 3
  </section>
</div>

关于html - 部分绝对位于彼此之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42274301/

相关文章:

javascript - 从输入字段 Javascript 获取值

jquery - 由于 JQuery DataTable 格式,Bootstrap 标签和字段对齐不起作用

css - 在字形图标上添加文本

html - 嵌套表的宽度不可更改

html - 如何将图像添加到自定义 CSS 按钮

html - 侧面导航中的 Angular Material 滑动过渡?

javascript - jQuery clone() 附加到多个元素而不是仅一个元素

javascript - 选择特定选项后禁用 select2 上的选项

javascript - HTML 刷卡登录

html - 让我的脚本和 CSS 页面与 MVC5 应用程序一起工作