Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- this is part of a study and not the final example, final example can be found here: https://codepen.io/utilitybend/pen/poWWaRv -->
<section class="scroll-snap-panel">
  <div class="tabs-container container">
    <button data-target="people-tab" class="people tab active">People</button>
    <button data-target="groups-tab" class="groups tab">Groups</button>
  </div>
  <div class="scroll-container container">
      <ul class="scroll-list people" id="people-tab">
        <li>
          <img src="http://placeimg.com/80/80/people?1" class="scroll-list-image" alt="" />
          <div>
            <h2>John Doe</h2>
            <small>Developer</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?8" class="scroll-list-image" alt="" />
          <div>
            <h2>Jane Doe</h2>
            <small>Front-end developer</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?3" class="scroll-list-image" alt="" />
          <div>
            <h2>Alfred Horus</h2>
            <small>Marketeer</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?4" class="scroll-list-image" alt="" />
          <div>
            <h2>Dane Dorenski</h2>
            <small>Director</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?5" class="scroll-list-image" alt="" />
          <div>
            <h2>Bass Strongarm</h2>
            <small>Functional analyst</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?6" class="scroll-list-image" alt="" />
          <div>
            <h2>Frederick Fancis</h2>
            <small>Technical analyst</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?7" class="scroll-list-image" alt="" />
          <div>
            <h2>Elise Berend</h2>
            <small>Ninja</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?8" class="scroll-list-image" alt="" />
          <div>
            <h2>Keith Wheelbarrow</h2>
            <small>Coffee snob</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?9" class="scroll-list-image" alt="" />
          <div>
            <h2>Oliver Greenwood</h2>
            <small>IT-support</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?10" class="scroll-list-image" alt="" />
          <div>
            <h2>Frank Demaska</h2>
            <small>Team lead</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?11" class="scroll-list-image" alt="" />
          <div>
            <h2>Frank Dorangeorgio</h2>
            <small>Sales</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?12" class="scroll-list-image" alt="" />
          <div>
            <h2>Marcus Webbers</h2>
            <small>OG</small>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/people?13" class="scroll-list-image" alt="" />
          <div>
            <h2>Mary Hercules</h2>
            <small>Geek</small>
          </div>
        </li>
      </ul>
      <ul class="scroll-list groups" id="groups-tab">
        <li>
          <img src="http://placeimg.com/80/80/arch?1" class="scroll-list-image" alt="" />
          <div>
            <h2>Developers</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?2" class="scroll-list-image" alt="" />
          <div>
            <h2>Analysts</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?3" class="scroll-list-image" alt="" />
          <div>
            <h2>IT-support</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?4" class="scroll-list-image" alt="" />
          <div>
            <h2>Designers</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?5" class="scroll-list-image" alt="" />
          <div>
            <h2>Project managers</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?6" class="scroll-list-image" alt="" />
          <div>
            <h2>Sales</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?6" class="scroll-list-image" alt="" />
          <div>
            <h2>Marketing</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?7" class="scroll-list-image" alt="" />
          <div>
            <h2>Team leads</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?7" class="scroll-list-image" alt="" />
          <div>
            <h2>Ninjas</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?8" class="scroll-list-image" alt="" />
          <div>
            <h2>Foodies</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?9" class="scroll-list-image" alt="" />
          <div>
            <h2>Hipsters</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?10" class="scroll-list-image" alt="" />
          <div>
            <h2>Geeks</h2>
          </div>
        </li>
        <li>
          <img src="http://placeimg.com/80/80/arch?11" class="scroll-list-image" alt="" />
          <div>
            <h2>Coffee snobs</h2>
          </div>
        </li>
      </ul>
  </div>
</section>
              
            
!

CSS

              
                :root {
  --container-width: 480px;
  --groups-bg: #8B008B;
  --people-bg: #4B0082;
  --groups-color: #FFF;
  --people-color: #F0FFFF;
  --main-bg: #FFFAF0;
}

.container {
  display: grid;
}

.scroll-snap-panel {
  width: 100%;
  margin: 0 auto;
  box-shadow: rgba(0, 0, 0, 0.3) 0px 10px 50px;
  max-width: var(--container-width);
}

/* the scroll magic */

.scroll-container {
  position: relative;
  grid-template-columns: repeat(2, var(--container-width));
  -webkit-overflow-scrolling: touch;
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  max-height: 85vh;
  border: 1px solid #CCC;
  border-top: 0;
}

.scroll-list {
  display: block;
  width: 100%;
  height: 80vh;
  margin: 0;
  padding: 0;
  list-style: none;
  scroll-snap-align: start;
  scroll-snap-type: y proximity;
  overflow-y: scroll;
}

.scroll-list > ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.scroll-list li {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 20px;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #aaa;
  scroll-snap-align: start;
}

/* styling of the inside of the list */

.scroll-list > li:last-child {
  border: 0;
}

.scroll-list-image {
  border-radius: 50%;
}

.people {
  background: var(--people-bg);
  color: var(--people-color);
}

.groups {
  background: var(--groups-bg);
  color: var(--groups-color);
}

/* some styling of the tabs */

.tabs-container {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 20px;
}

.tab {
  display: block;
  margin: 0;
  padding: 16px 8px;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  color: #FFF;
  border: 1px solid #CCC;
  border-left: 0;
  cursor: pointer;
}

.tab:first-child {
  border-top-left-radius: 5px;
  border: 1px solid #CCC;
}

.tab:last-child {
  border-top-right-radius: 5px;
}

.tab.active {
  border-bottom-color: transparent;
}

/* some basic styling (added to the bottom for convenience) */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Lato', sans-serif;
  font-size: 1.2rem;
  line-height: 1.5;
  color: #FEFEFE;
  background: var(--main-bg);
}

img {
  max-width: 100%;
  margin: 0;
}

h2 {
  margin: 0;
  font-family: 'Merriweather', serif;
  font-size: 1.5rem;
  line-height: 1.2;
}

              
            
!

JS

              
                const tabs = document.querySelectorAll(".tab");
const scrollContainer = document.querySelector(".scroll-container");
const scrollLists = document.querySelectorAll(".scroll-list");

/* check for clicks and update scroll position based on target offset */
tabs.forEach((tab) => {
  tab.addEventListener("click", () => {
    const target = document.getElementById(tab.dataset.target).offsetLeft;
    scrollContainer.scrollLeft = target;
  });
});

/* when the scrollcontainer is scrolled horizontally, check the current scrollposition is the same as the left offset, and set the tab active when that's the case */
scrollContainer.addEventListener("scroll", () => {
  let scrollPos = scrollContainer.scrollLeft;

  scrollLists.forEach((list) => {
    let listId = list.id;
    let listButton = document.querySelector(`.tab[data-target="${listId}"]`);
    if (scrollPos === list.offsetLeft) {
      [...listButton.parentElement.children].forEach((sib) => {
        sib.classList.remove("active");
      });
      listButton.classList.add("active");
    }
  });
});

              
            
!
999px

Console