Can Multiple Sticky Elements Be Stacked in Pure CSS?

DDD
Release: 2024-10-31 18:57:02
Original
494 people have browsed it

Can Multiple Sticky Elements Be Stacked in Pure CSS?

Is it possible to have multiple sticky elements stacked on top of each other in pure CSS?

The desired behavior can be seen here:
https://webthemez.com/demo/sticky-multi-header-scroll/index.html

Only I'd prefer to use pure CSS, instead of a Javascript implementation. I've experimented a bit with multiple sticky elements, but I can't keep them from pushing out other sticky elements. I've tried placing them in the same stacking context:

<code class="css">#sticky .sticky-1,
#sticky .sticky-2
{
  position: sticky;
}
#sticky .sticky-1
{
  top: 1em;
  z-index: 1;
}
#sticky .sticky-2
{
  top: 2em;
  z-index: 1;
}</code>
Copy after login

But can't get it to work, as you can see in below. Any insights would be greatly appreciated!

<code class="html"><div id="container">
  <article id="sticky">
    <header>

    </header>
    <main><h1 class="sticky-1">Sticky heading</h1></code>
Copy after login

The above is the detailed content of Can Multiple Sticky Elements Be Stacked in Pure CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!