css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <article class="page">

  <article class="main">
    <div class="scroll-intro" id="intro">
      <div class="inner">
        <h1>CSS Scroll Snap Points Example</h1>
        <div class="supports" id="supports"></div>
        <h2>Responsive Vertical Scroll Gallery – Same Sized Images</h2>
        <p>Below is a gallery where all images are the same size and will be scrolled vertically. With scroll snapping we can make it so that as you scroll the container, the browser will snap the scroll to 100% high, showing the entire image. This gallery
          is responsive, it's width will change depending on the screen size (up to a set maximum)</p>
      </div>
    </div>
    <div class="inner">
      <div class="scroll-container same-size">
        <div class="wrap">
          <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/snapsquare01.jpg">
        </div>
        <div class="wrap">
          <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/snapsquare02.jpg">
        </div>
        <div class="wrap">
          <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/snapsquare03.jpg">
        </div>
        <div class="wrap">
          <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/snapsquare04.jpg">
        </div>
      </div>
    </div>
  </article>
  <p class="p">Demo by Simon Codrington. <a href="http://www.sitepoint.com/intuitive-scrolling-interfaces-with-css-scroll-snap-points">See article</a>.</p>
</article>
            
          
!
            
              /*UNIVERSAL STYLES*/

html {
  font-size: 62.5%;
}

body {
  font-weight: 400;
  font-style: normal;
  font-size: 1.5rem;
  line-height: 1.5rem;
  color: #333;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 150%;
  margin: 1.5rem 0rem;
}

h1 {
  font-size: 3.8rem;
  margin: 0;
}

h2 {
  font-size: 2.8rem;
  margin: 0;
  line-height: 1.3;
}

h3 {
  font-size: 2.1rem;
  margin: 0;
}

h4 {
  font-size: 1.8rem;
}

h5 {
  font-size: 1.3rem;
}

h6 {
  font-size: 1.0rem;
}

p {
  margin: 0rem 0rem 2.4rem 0rem;
  line-height: 170%;
}

ul {
  line-height: 150%;
}

ul li {
  margin-bottom: 10px;
}
/*clearfixes*/

.cf:before,
.cf:after {
  content: " ";
  display: table;
}

.cf:after {
  clear: both;
}

*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
/*block level elements*/

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section,
div {
  margin: 1.5rem 0rem;
}

div {
  margin: 0rem;
}

.page {
  margin: 0px;
  padding: 0px;
}

.main {
  margin: 0px;
  padding: 0px;
  max-width: none;
}

.inner {
  max-width: 1000px;
  margin: auto;
  padding-left: 15px;
  padding-right: 15px;
}

.failure {
  color: red;
}

.success {
  color: green;
}

.notes {
  margin-bottom: 50px;
}
/*SCROLL SNAP SYLES*/

.scroll-container {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  width: auto;
  height: 400px;
  scroll-snap-type: mandatory;
  scroll-behavior: smooth;
  font-size: 0px;
}

.scroll-container .scroll-section {
  display: inline-block;
  vertical-align: middle;
  background: #fff;
  border: solid 1px #ccc;
}

.scroll-container.same-size {
  padding-bottom: 50%;
  height: 0px;
  width: 50%;
  scroll-snap-points-y: repeat(calc(100% + 17px));
}

.scroll-container.same-size .wrap {
  position: relative;
  height: auto;
  width: 100%;
  width: calc(100% + 17px);
  padding: 0px;
  display: inline-block;
  white-space: nowrap;
}

.scroll-container.same-size .scroll-section {
  height: 100%;
  width: 100%;
  border: solid 1px #ccc;
  background: #eee;
  padding: 15px;
}
/*Small screens*/

@media screen and (max-width: 643px) {
  .scroll-container.same-size {
    width: 100%;
    padding-bottom: 100%;
  }
}

.p {
  text-align: center;
  padding-top: 80px;
  font-size: 13px;
}
            
          
!
            
              $(function() {

  //detect if we support scroll snap or not (not the best but should work)
  var scrollSnap = false;
  scrollSnap = 'webkitScrollSnapType' in document.documentElement.style;
  scrollSnap = 'scrollSnapType' in document.documentElement.style;

  if (scrollSnap === true) {
    $('#supports').append('<h3 class="success">It looks like your browser does support scroll snap!</h3>');
  } else {
    $('#supports').append('<h3 class="failure">It looks like your browser might not support scroll snap properties</h3>');
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console