← All elements

Sticky Stacking Cards

by @admin · 5 views

<div class="pc-stack" tabindex="0" aria-label="Store promises">
  <article class="pc-stack__card" style="--i:0">
    <h3>Free returns</h3>
    <p>Send it back within 30 days.</p>
  </article>
  <article class="pc-stack__card" style="--i:1">
    <h3>Gift wrapping</h3>
    <p>Added at checkout, free.</p>
  </article>
  <article class="pc-stack__card" style="--i:2">
    <h3>Local pickup</h3>
    <p>Ready in two hours.</p>
  </article>
  <article class="pc-stack__card" style="--i:3">
    <h3>Repairs</h3>
    <p>We mend what we sell.</p>
  </article>
</div>

About this layout

A scrolling list where position: sticky with a per-card offset makes each card slide over the last one and leave a visible edge.

How it works

Each card is position: sticky with a top offset of 8px plus 16px per card, set from the --i custom property. As you scroll the panel, every card sticks a little lower than the one before and the next card slides over it, leaving a strip of each earlier card visible, so the cards appear to stack.

Ways to customise it

  • Change the 16px step in the top calc for tighter or looser stacking.
  • Change the 150px card height.
  • Change the four background colours in the nth-child rules.

Good to know

The scrolling panel has tabindex=0 and a label so keyboard users can focus and scroll it. Sticky positioning needs the scroll container to have a fixed height, which is why the panel has one.

Open an example, copy the HTML and the CSS, and paste them into your page. There is nothing to install and no JavaScript to load.

More in Layout

View all →