<section>
<h1>Section 1</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias, sint fuga ipsam soluta maxime in est ipsa modi explicabo impedit natus, dolore eum, voluptas sequi dicta ullam placeat expedita quos.</p>
</section>
<section>
<h1 class="position-sticky" style="z-index: 2;top:10%">Section 2</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias, sint fuga ipsam soluta maxime in est ipsa modi explicabo impedit natus, dolore eum, voluptas sequi dicta ullam placeat expedita quos.</p>
</section>
<section>
<h1>Section 3</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias, sint fuga ipsam soluta maxime in est ipsa modi explicabo impedit natus, dolore eum, voluptas sequi dicta ullam placeat expedita quos.</p>
</section>
1条答案
按热度按时间s2j5cfk01#
你可以通过固定主导航栏来实现这一点,或者粘性并不重要。只需将所需标题的位置设置为
position-sticky
,而不是sticky-top
,因为sticky-top
会粘在您不想要的顶部。您需要的是主服务器下方的辅助导航栏,这样css
将有助于将top
设置为12%
或任何您需要的设置,只需测试它即可。这是jsFiddle链接。