【问题标题】:Hiding content behind action bar将内容隐藏在操作栏后面
【发布时间】:2023-03-24 16:35:01
【问题描述】:

我试图让内容在滚动时隐藏在操作栏后面。
我有这个示例笔: https://codepen.io/Wocha/pen/ExKVNRW

HTML:

  <div class="app-content">
  <div class="main-content">
    <div class="content">
      Some main content
    </div>
    <div class="footer">
      Footer content
    </div>
  </div>
</div>

CSS:

body {
  background: #F2F3F5;
}

.app-content {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: stretch;
  padding: 0;
  margin-top: 60px;
}

.main-content {
  width: 100%;
  margin: 0;
  padding-left: 16px;
  padding-right: 16px;
}

.content {
  background: #fff;
  padding: 16px;
  min-height: 82vh;
  width: 100%;
  margin-bottom: 25px;
}

.footer {
  display: block;
  position: sticky;
  bottom: 15px;
  width: 100%;
  color: #fff;
  background: #000;
  padding: 10px;
  margin-top: 20px;
}

我希望内容在滚动时隐藏在页脚/操作栏后面,以便在页脚和内容之间总是有一条可见的背景灰色线。

我可以通过设置内容高度和溢出来做到这一点:自动,但这会为内容 div 创建额外的滚动条,我希望它在滚动主窗口时工作。

这篇文章非常接近我想要发生的事情,但是操作栏只是滚动内容,与我的笔示例相同。
Fixed action bar, taking footer into account

【问题讨论】:

  • 所以你想要主要内容和页脚之间的灰色小边框?或者您希望主要内容在页脚下方不可见?我做对了吗?
  • 操作栏粘在底部。滚动时,我希望主要内容在操作栏后面不可见。灰色线(背景)将是添加到操作栏的少量填充。
  • 您可以制作一个与您的背景颜色相同的 div 并将其放在页脚下方。然后将其位置也设置为固定并将 z-index 设置为 1
  • 试过这个解决方案,但看起来有点奇怪,因为主要内容在底部边框格式的段内。目前放弃并像示例中一样离开它。

标签: javascript html css


【解决方案1】:

将操作栏的 z 索引更改为 1

z-index: 1;

【讨论】:

  • 设置 z-index 不会改变行为。当我滚动内容时,它仍然在操作栏后面可见。
猜你喜欢
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-18
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多