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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <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>
              
            
!

CSS

              
                /*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;
}
              
            
!

JS

              
                $(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

Console