小编Ro *_*erg的帖子

纯CSS的多个堆叠位置是否粘滞?

在纯CSS中是否可以将多个粘性元素彼此堆叠?

可以在此处看到所需的行为:https : //webthemez.com/demo/sticky-multi-header-scroll/index.html

只有我更喜欢使用纯CSS,而不是Javascript实现。我已经对多个粘性元素进行了一些实验,但是不能阻止它们推出其他粘性元素。我试过将它们放在相同的堆栈上下文中:

#sticky .sticky-1,
#sticky .sticky-2
{
  position: sticky;
}
#sticky .sticky-1
{
  top: 1em;
  z-index: 1;
}
#sticky .sticky-2
{
  top: 2em;
  z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)

但是无法正常工作,如下所示。任何见解将不胜感激!

#sticky .sticky-1,
#sticky .sticky-2
{
  position: sticky;
}
#sticky .sticky-1
{
  top: 1em;
  z-index: 1;
}
#sticky .sticky-2
{
  top: 2em;
  z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
<article id="sticky">
  <header>
  
  </header>
  <main><h1 class="sticky-1">Sticky heading</h1>
  <p>here. Some copy goes here. Some copy goes here. Some copy goes here. Some copy goes …
Run Code Online (Sandbox Code Playgroud)

css css-position sticky

3
推荐指数
2
解决办法
5766
查看次数

标签 统计

css ×1

css-position ×1

sticky ×1