我有一个侧边栏,我有一个固定元素,但当它到达页脚,固定元素去了顶部我的页脚,我真正希望的是,如果固定元素停止滚动的权利之前,页脚:
<div class="container">
<div class="row">
<div class="col-md-8">Blah Blah Blah</div>
<div class="col-md-4 related-podcasts">
<ul class="podcast-list">
<li><i class="fa-solid fa-podcast"></i> Lorem ipsum dolor sit amet - In aliquet</li>
<li><i class="fa-solid fa-podcast"></i> Lorem ipsum dolor sit amet - In aliquet</li>
<li><i class="fa-solid fa-podcast"></i> Lorem ipsum dolor sit amet - In aliquet</li>
<li><i class="fa-solid fa-podcast"></i> Lorem ipsum dolor sit amet - In aliquet</li>
<li><i class="fa-solid fa-podcast"></i> Lorem ipsum dolor sit amet - In aliquet</li>
</ul>
</div>
</div>
</div>
<footer style="height:200px; color: black;"></footer>
下面是CSS:
.related-podcasts {
position: fixed;
width: 33.33333333%;
right: 0px;
z-index: 1;
}
使用jQuery或CSS,当这个固定元素到达页脚时,我如何将其转换为绝对元素,使其不超过页脚的顶部?
1条答案
按热度按时间s4n0splo1#
你可以不用任何javascript就可以做到。使用position:sticky和top value添加到相关播客类,如下所示: