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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
              <main>
  <h1>Easy Scroll Snapping Carousel</h1>

  <h2>CSS Flexbox-based layout</h2>
  <ul class="scroll-container" data-layoutmethod="flexbox">
    <li class="scroll-item">A</li>
    <li class="scroll-item">B</li>
    <li class="scroll-item">C</li>
    <li class="scroll-item">D</li>
    <li class="scroll-item">E</li>
    <li class="scroll-item">F</li>
    <li class="scroll-item">G</li>
  </ul>

  <h2>CSS Grid-based Layout</h2>
  <ul class="scroll-container" data-layoutmethod="grid">
    <li class="scroll-item">A</li>
    <li class="scroll-item">B</li>
    <li class="scroll-item">C</li>
    <li class="scroll-item">D</li>
    <li class="scroll-item">E</li>
    <li class="scroll-item">F</li>
    <li class="scroll-item">G</li>
  </ul>
</main>
            
          
!

CSS

            
              /* limit width so that content will need to scroll */
main {
  max-width: 30em;
}

/* SCROLL SNAPPING */
.scroll-container {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.scroll-item {
  scroll-snap-align: center;
}
/* make 3rd item bigger to show that items don't need to have the same width */
.scroll-item:nth-child(3) {
  width: 15em;
}
/* make 5th item bigger to show that items don't need to have the same width */
.scroll-item:nth-child(5) {
  height: 15em;
}

/* FLEXBOX LAYOUT */
.scroll-container[data-layoutmethod="flexbox"] {
  display: flex;
  flex-wrap: nowrap;
  align-items: center; /* vertically align children */
}
.scroll-container[data-layoutmethod="flexbox"] .scroll-item {
  margin-right: 1em; /* fake gap */
  flex: 0 0 auto;
}

/* GRID LAYOUT */
.scroll-container[data-layoutmethod="grid"] {
  display: grid;
  grid: auto / auto-flow max-content;
  grid-gap: 1em;
  align-items: center; /* vertically align children */
}

/** OTHER STYLES **/
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  text-rendering: optimizeLegibility;
  margin: 0;
  padding: 0;
}

/* center main element */
main {
  margin: 0 auto;
  padding: 0 1em;
  border: 1px solid rgba(0,0,0,0.1);
}

/* remove list styles */
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.scroll-item {
  /* make it square */
  width: 10em;
  height: 10em;
  border: 1px solid rgba(0,0,0, 0.1);

  /* some basic styling */
  background: #ccc;
  border-radius: 0.2em;

  /* center contents */
  display: flex;
  justify-content: center;
  align-items: center;
}
            
          
!

JS

            
              
            
          
!
999px

Console