Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Pure CSS scrolling shadows with <code>background-attachment: local;</code></h1>

<p><em><a href="http://lea.verou.me/2012/04/background-attachment-local/" target="_blank">Lea's approach</a>, but also applied to a horizontal scroll container (and using CSS Custom Properties)</em></p>

<h2>Vertical Scroll Container</h2>

<div class="scrollcontainer scrollcontainer--vertical">
  <div class="scrollcontainer__content">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur sit amet ipsum eget aliquet. Suspendisse vitae lacinia ligula. Donec fringilla, nisl non pharetra ornare, metus nibh sagittis eros, vel porta mauris leo sodales quam. Nulla nec diam cursus, suscipit mauris quis, scelerisque felis. Duis sollicitudin nulla at libero porttitor, ut efficitur elit consequat. Morbi fringilla gravida ullamcorper. Cras vehicula sapien ac tellus scelerisque vehicula. Phasellus rhoncus sem eu ultricies aliquet. Suspendisse non justo at eros lacinia congue. Donec laoreet ultrices ultrices. Nulla velit velit, aliquet quis blandit sodales, suscipit scelerisque tortor. Donec non aliquet ipsum, sit amet tempus lorem. Pellentesque euismod suscipit ultricies.</p>
    <p>Nunc in blandit metus, sit amet iaculis nulla. Pellentesque lacinia diam sed enim gravida vehicula. Praesent ac nisi sit amet nisl sodales elementum. Etiam vitae nunc at nibh condimentum finibus non convallis mauris. Fusce pretium dui eu est fringilla, ut ultricies nunc euismod. Aliquam elementum cursus urna nec vehicula. Sed ac ligula velit. Morbi leo nulla, efficitur ut leo eget, porttitor egestas ex. Pellentesque viverra ligula interdum, fringilla magna eu, ultrices mi. Proin nulla quam, malesuada fringilla vulputate sit amet, condimentum et mauris. Etiam ante dolor, ultrices at lobortis in, iaculis sit amet eros.</p>
  </div>
</div>

<h2>Horizontal Scroll Container</h2>

<div class="scrollcontainer scrollcontainer--horizontal">
    <div class="scrollcontainer__content">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur sit amet ipsum eget aliquet. Suspendisse vitae lacinia ligula. Donec fringilla, nisl non pharetra ornare, metus nibh sagittis eros, vel porta mauris leo sodales quam. Nulla nec diam cursus, suscipit mauris quis, scelerisque felis. Duis sollicitudin nulla at libero porttitor, ut efficitur elit consequat. Morbi fringilla gravida ullamcorper. Cras vehicula sapien ac tellus scelerisque vehicula. Phasellus rhoncus sem eu ultricies aliquet. Suspendisse non justo at eros lacinia congue. Donec laoreet ultrices ultrices. Nulla velit velit, aliquet quis blandit sodales, suscipit scelerisque tortor. Donec non aliquet ipsum, sit amet tempus lorem. Pellentesque euismod suscipit ultricies.</p>
    <p>Nunc in blandit metus, sit amet iaculis nulla. Pellentesque lacinia diam sed enim gravida vehicula. Praesent ac nisi sit amet nisl sodales elementum. Etiam vitae nunc at nibh condimentum finibus non convallis mauris. Fusce pretium dui eu est fringilla, ut ultricies nunc euismod. Aliquam elementum cursus urna nec vehicula. Sed ac ligula velit. Morbi leo nulla, efficitur ut leo eget, porttitor egestas ex. Pellentesque viverra ligula interdum, fringilla magna eu, ultrices mi. Proin nulla quam, malesuada fringilla vulputate sit amet, condimentum et mauris. Etiam ante dolor, ultrices at lobortis in, iaculis sit amet eros.</p></div>
</div>

<p><em>Source: <a href="https://www.bram.us/2019/10/24/pure-css-scroll-shadows-vertical-horizontal/" target="_top">https://www.bram.us/2019/10/24/pure-css-scroll-shadows-vertical-horizontal/</a></em></p>
              
            
!

CSS

              
                body {
  background: white;
  font-family: sans-serif;
  text-align: center;
  padding: 1em;
}

.scrollcontainer {
  margin: 0 auto;
  height: 10em;
  width: 40em;
  border: 1px solid #ccc;
  
  --background-color: rgba(255, 255, 255, 1);
  --shadow-color: rgba(34,34,34, 0.5);
  --shadow-size: 0.75em;
  --transparent: rgba(255, 255, 255, 0); /* We can't use "transparent" directly, because Safari would interpret the color as "transparent black" (see https://css-tricks.com/thing-know-gradients-transparent-black/). Using this workaround, it works fine. */
}

.scrollcontainer__content {
  padding: 0 1em;
  text-align: left;
}

.scrollcontainer--vertical {
  overflow-y: scroll;

  background: 
    linear-gradient(var(--background-color), var(--background-color), var(--transparent) calc(var(--shadow-size) * 2)),
    radial-gradient(farthest-side at 50% 0, var(--shadow-color), var(--transparent)),
    linear-gradient(to top, var(--background-color), var(--background-color), var(--transparent) calc(var(--shadow-size) * 2)),
    radial-gradient(farthest-side at 50% 100%, var(--shadow-color), var(--transparent)) 0 100%;
  background-color: var(--background-color);
  background-repeat: no-repeat;
  background-attachment: local, scroll,local,  scroll;
  background-size: 100% 100%, 100% var(--shadow-size), 100% 100%, 100% var(--shadow-size);
}

.scrollcontainer--horizontal {
  overflow-x: scroll;

  background:
    linear-gradient(to right, var(--background-color), var(--background-color), var(--transparent) calc(var(--shadow-size) * 2)),
    radial-gradient(farthest-side at 0 50%, var(--shadow-color), var(--transparent)),
    linear-gradient(to left, var(--background-color), var(--background-color), var(--transparent) calc(var(--shadow-size) * 2)),
    radial-gradient(farthest-side at 100% 50%, var(--shadow-color), var(--transparent)) 100%;
  background-color: var(--background-color);
  background-repeat: no-repeat;
  background-attachment: local, scroll, local, scroll;
  background-size: 100% 100%, var(--shadow-size) 100%, 100% 100%, var(--shadow-size) 100%;
  height: 100%;
}

.scrollcontainer--horizontal .scrollcontainer__content {
  white-space: nowrap;
}



h2, div + p {
  margin-top: 4em;
}
              
            
!

JS

              
                // Fix for Mobile Safari that doesn't correctly re-render backgrounds during scroll
// @ref https://bugs.webkit.org/show_bug.cgi?id=181048
// Alternative fix, using only CSS: https://codepen.io/bramus/pen/RwgXxJv
// UPDATE: Seems to have stopped working in iOS 15 😭😭
if (CSS.supports("-webkit-overflow-scrolling: touch")) {
  document.querySelectorAll(".scrollcontainer").forEach((scroller) => {
    scroller.addEventListener("scroll", () => {
      scroller.style.setProperty("--force-paint", Date.now());
    });
  });
}

              
            
!
999px

Console