html - CSS - 覆盖 div 高度 :100% including scroll area is not working

标签 html css scrollbar overflow overlay

我正在尝试做一些非常简单的事情。
我有带滚动功能的 div,我希望覆盖 div 覆盖所有高度包括滚动区域 . 我试过 min-height:100%(就像在 this question 中一样)但它不起作用。

这是一个例子 https://jsfiddle.net/svfukxjd/2/

.main {
  height: 300px;
  width: 150px;
  background: red;
  overflow: auto;
  position: relative;
}
.cover {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  bottom: 0;
  background: green;
  opacity: 0.5;
}
<div class="main">
  <div>
    Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
  </div>
  <div class="cover">

  </div>
</div>

最佳答案

  1. 添加 cover 作为包含您的内容的 div 的子元素。

  2. 相对于内容 div 的位置 cover 使用:

    .main > div {
      position: relative;
    }
    

让我知道您对此的反馈。谢谢!

.main {
  height: 300px;
  width: 150px;
  background: red;
  overflow: auto;
  position: relative;
}
.main > div {
  position: relative;
}
.cover {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  bottom: 0;
  background: green;
  opacity: 0.5;
}
<div class="main">
  <div>
    Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <br>Test
    <div class="cover">
    </div>
  </div>
</div>

关于html - CSS - 覆盖 div 高度 :100% including scroll area is not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40125506/

相关文章:

javascript - 如何将 anchor 链接列表转换为选择下拉列表,在选项更改时操作更改选项卡?

jquery - jQuery函数需要添加什么?

html - CSS - 定位 Div

css - 如何让子元素的最小宽度/最大宽度忽略父元素的宽度?

javascript - 顶部菜单在 div 滚动条上显示和隐藏

python - 水平滚动条在 Tkinter 中不起作用

c++ - 如何使用 WinAPI 在 Windows 上自定义滚动条

javascript - 按住键后 Jquery/JS : skip N items from siblings. 错误

javascript - 我怎样才能使 "Wait, it' s 处理..!”系统?

javascript - 有没有办法在滚动条上放置标记?