【问题标题】:Transformed elements will not display behind an element with position sticky转换后的元素不会显示在位置粘滞的元素后面
【发布时间】:2021-08-23 06:17:29
【问题描述】:

我不太确定我在这里缺少什么。 我有一个粘性标题。除已转换的内容外,所有内容都在其后面流动。

向下滚动页面时,转换后的“A”会显示在标题的顶部,而它应该在它的后面。

.sticky-header {
  position:sticky;
  top:0;
  background: red;
  height: 250px;
}

.some-content {
  background:blue;
  height:1000px;
  text-align:center;
}

p {
  color:white;
  font-size: 60px;
}

.transformed {
  transform: rotate(180deg)
}
<div class="sticky-header">
</div>
<div class="some-content">
  <p>A</p>
  <p class="transformed">A</p>
  <p>A</p>
</div>

Link to codepen

【问题讨论】:

    标签: html css css-position sticky


    【解决方案1】:

    添加:

    .sticky-header {index: 1;}
    

    MDN :“z-index CSS 属性设置定位元素及其后代或弹性项目的 z 顺序。具有较大 z-index 的重叠元素覆盖具有较小 z-index 的元素”。

    查看更多关于z-index

    .sticky-header {
      position:sticky;
      top:0;
      background: red;
      height: 250px;
      z-index: 1;
    }
    
    .some-content {
      background:blue;
      height:1000px;
      text-align:center;
    }
    
    p {
      color:white;
      font-size: 60px;
    }
    
    .transformed {
      transform: rotate(180deg)
    }
    <div class="sticky-header">
    </div>
    <div class="some-content">
      <p>A</p>
      <p class="transformed">A</p>
      <p>A</p>
    </div>

    【讨论】:

    • 是的,做到了。谢谢!
    • Np,如果您发现此答案有帮助,我们将不胜感激:)
    猜你喜欢
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多