有一个div(即div_fixed)是固定位置的。另一个div就是other_content在div_fixed. other_contentdiv 有一个属性,padding-top因此当页面滚动时,只有other_content在固定 div 下方滚动。
小提琴在这里
HTML:
<div class="div_fixed">FIXED</div>
<div class="other_content">
content goes here<br/>
content goes here<br/>
content goes here<br/>
</div>
CSS:
div { color: #fff }
.div_fixed { position: fixed;
width: 100%;
height: 100px;
}
.other_content {
background: #f00;
height: 5000px;
color: #fff;
padding-top: 100px;
margin:0 auto;
}
但我希望非固定 div 保持在固定 div 上,并希望非固定 div 在其上边缘下方消失,即非固定 div 上边缘的位置将保持固定,但它的内容将在页面滚动时开始消失就像它停留在固定 div 下方时发生的那样。
因此,在非固定 div 之前,我在 html 中进行了一些编辑(只有 2 个中断):
<div class="div_fixed">FIXED</div>
<br><br/>
<div class="other_content">
content goes here<br/>
content goes here<br/>
content goes here<br/>
</div>
css中的补充是:
.fixed_div{
z-index:-1;
}
.other_content{
width:60%;
z-index:99099900;
}
但是非固定div的上边缘并没有停留在我想要的位置。
如何做到这一点?
编辑:
假设我为非固定的div. 是否有可能固定的背景图像的一部分, div其他 div 将滚动的部分将z-index高于非固定的div?问题会这样解决吗?
编辑2
让我们假设它fixed_div是标题,other_content是网页的内容主体。让我们添加一个div带有 id的页脚footer。中不应出现滚动other_content。other_content滚动页面时应该滚动。