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

              
                <!--  gallery 1 -->
<div class="gallery">
  <ul class="gallery__nav gallery__nav1">
    <li class="is-active">Cat</li>
    <li>Contrail</li>
    <li>Drizzle</li>
    <li>Grapes</li>
  </ul>

  <div class="gallery__tab-container gallery__tab-container1">
    <div class="gallery__tab gallery__tab1 is-active">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/cat-nose.jpg" />
      <p>Close up cat nose</p>
    </div>
    <div class="gallery__tab gallery__tab2">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/contrail.jpg" />
      <p>Passing overhead we sailed into tomorrow</p>
    </div>
    <div class="gallery__tab gallery__tab3">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/drizzle.jpg" />
      <p>I heard the rain wash the streets</p>
    </div>
    <div class="gallery__tab gallery__tab4">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/grapes.jpg" />
      <p>Oh the grapes, they had so much WRATH</p>
    </div>
  </div>
</div>

<!--  gallery 2 -->
<div class="gallery">
  <ul class="gallery__nav gallery__nav2">
    <li class="is-active">Oranges</li>
    <li>Shore</li>
    <li>Submerged</li>
    <li>Tulip</li>
  </ul>

  <div class="gallery__tab-container gallery__tab-container2">
    <div class="gallery__tab gallery__tab1 is-active">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/orange-tree.jpg" />
      <p>Pluck an orange from the tree</p>
    </div>
    <div class="gallery__tab gallery__tab2">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/shore.jpg" />
      <p>Approaching the shoreline, waiting for the tide</p>
    </div>
    <div class="gallery__tab gallery__tab3">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/submerged.jpg" />
      <p>Beneath the waves he could still hear them calling</p>
    </div>
    <div class="gallery__tab gallery__tab4">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/tulip.jpg" />
      <p>A present from a dewey morning</p>
    </div>
  </div>
</div>

<!--  gallery 3 -->
<div class="gallery">
  <ul class="gallery__nav gallery__nav3">
    <li class="is-active">Van</li>
    <li>Golden hour</li>
    <li>Flight</li>
    <li>Leaf droplets</li>
  </ul>

  <div class="gallery__tab-container gallery__tab-container3">
    <div class="gallery__tab gallery__tab1 is-active">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/van.jpg" />
      <p>Get in. I'll explain on the road.</p>
    </div>
    <div class="gallery__tab gallery__tab2">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/golden-hour.jpg" />
      <p>Sun's down. Hun's down.</p>
    </div>
    <div class="gallery__tab gallery__tab3">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/flight-formation.jpg" />
      <p>Upwards we soared</p>
    </div>
    <div class="gallery__tab gallery__tab4">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/leaf-droplets.jpg" />
      <p>Must have rained</p>
    </div>
  </div>
</div>

              
            
!

CSS

              
                body { font-family: sans-serif; }

.gallery__nav {
  padding: 0;
  display: -webkit-box;
  display: flex;
  flex-wrap: wrap;
}

.gallery__nav li {
  display: block;
  padding: 10px;
  border: 1px solid #DDD;
  margin-right: -1px;
  text-decoration: none;
  cursor: pointer;
  color: #08E;
}

.gallery__nav li:hover {
  background: #EEE;
}

.gallery__nav li.is-active {
  background: #19F;
  color: white;
}

.gallery__tab {
  display: none;
  margin-bottom: 40px;
}

.gallery__tab.is-active {
  display: block;
}

.gallery__tab img {
  display: block;
  height: 240px;
}

              
            
!

JS

              
                $('.gallery').each( function( index ) {
  var number = index + 1;
  var $activeNavItem = $( '.gallery__nav' + number + ' li.is-active' );
  var $activeTab = $( '.gallery__tab-container' + number + ' .gallery__tab.is-active' );
  console.log( index )
  $( '.gallery__nav' + number ).on( 'click', 'li', function( event ) {
    event.preventDefault();
    var $navItem = $( event.currentTarget );
    // update active nav item
    $activeNavItem.removeClass('is-active');
    $activeNavItem = $navItem.addClass('is-active');
    // update active tab
    $activeTab.removeClass('is-active');
    var tabNumber = $navItem.index() + 1; // 1,2,3..
    $activeTab = $( '.gallery__tab-container' + number + ' .gallery__tab' + tabNumber );
    $activeTab.addClass('is-active');
  });
});

              
            
!
999px

Console