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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <section class="js-horizontal-collapse  horizontal-collapse" data-item-min-width="150" data-item-max-width="500">
  <ul class="horizontal-collapse__inner">
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--1" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">One inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">One active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate? Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
          <a class="horizontal-collapse__link" href="https://codepen.io/" target="_top">CodePen Home</a>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--2" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Two inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Two active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--3" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Three inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Three active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--4" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Four inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Four active</h2>
          <p class="horizontal-collapse__body"></p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--5" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Five inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Five active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
  </ul>
</section>

<section class="js-horizontal-collapse  horizontal-collapse" data-item-min-width="150" data-item-max-width="500">
  <ul class="horizontal-collapse__inner">
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--1" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">One inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">One active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate? Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--2" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Two inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Two active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--3" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Three inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Three active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--4" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Four inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Four active</h2>
          <p class="horizontal-collapse__body"></p>
        </div>
      </div>
    </li>
    <li class="js-horizontal-collapse-item  horizontal-collapse__item  horizontal-collapse__item--5" tabindex="0" role="button">
      <div class="js-horizontal-collapse-item-inner  horizontal-collapse__item-inner">
        <div class="horizontal-collapse__inactive-content">
          <h2 class="horizontal-collapse__heading">Five inactive</h2>
        </div>
        <div class="horizontal-collapse__active-content">
          <h2 class="horizontal-collapse__heading">Five active</h2>
          <p class="horizontal-collapse__body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates modi laudantium facere aut, nemo praesentium, labore doloremque, porro ipsam qui nihil animi ea maiores. Ut excepturi quae veritatis. Recusandae, cupiditate?</p>
        </div>
      </div>
    </li>
  </ul>
</section>
              
            
!

CSS

              
                $transitionDurationMs: 0.5s;

*, *:before, *:after {
  box-sizing: inherit;
}

html {
  box-sizing: border-box;
  font-size: 10px;
}

body {
  font-size: 1.6rem;
}

.horizontal-collapse {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin-bottom: 5rem;
  color: #fff;

  &__inner {
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: row;
  }
  
  &__item {
    min-height: 42rem;
    list-style: none;
    padding: 0;
    overflow: hidden;
    min-width: 10rem;
    max-width: 40rem;
    position: relative;
    transition: width $transitionDurationMs;
    
    &--1 {
      background-color: red;
    }
    
    &--2 {
      background-color: green;
    }
    
    &--3 {
      background-color: blue;
    }
    
    &--4 {
      background-color: purple;
    }
    
    &--5 {
      background-color: orange;
    }
    
    &.is-active {
      // color: #fff;
      
      .horizontal-collapse__inactive-content {
        opacity: 0;
      }
      
      .horizontal-collapse__active-content {
        opacity: 1;
      }
    }
  }
  
  &__item-inner {
    padding: 3rem;
  }
  
  &__inactive-content {
    opacity: 1;
    transition: opacity $transitionDurationMs;
    position: absolute;
    bottom: 2rem;
    left: 1rem;
    
    .horizontal-collapse__heading {
      user-select: none;
      cursor: default;
      font-size: 3rem;
      line-height: 0;
      margin-bottom: 0;
      writing-mode: vertical-rl;
      text-orientation: mixed;
      transform: rotate(180deg);
    }
  }
  
  &__active-content {
    opacity: 0;
    transition: opacity $transitionDurationMs;
    cursor: default;
  }
  
  &__heading {
    margin-top: 0;
    margin-bottom: 2rem;
  }
  
  &__body {
    margin-bottom: 2rem;
  }
  
  &__link {
    display: inline-block;
    background-color: #fff;
    color: #333;
    text-decoration: none;
    line-height: 1;
    padding: 1rem 2rem;
    border-radius: 2rem;
    font-size: 1.7rem;
    font-weight: bold;
  }
}
              
            
!

JS

              
                $(function() {
  var $horizontalCollapse = $('.js-horizontal-collapse');
  
  $horizontalCollapse.each(function() {
    var $hc = $(this);
    var itemMinWidth = $hc.data('itemMinWidth');
    var itemMaxWidth = $hc.data('itemMaxWidth');
    var $items = $hc.find('.js-horizontal-collapse-item');
    $items.each(function() {
      var $item = $(this);
      $item.css('min-width', itemMinWidth + 'px');
      $item.css('width', itemMinWidth + 'px');
      $item.css('max-width', itemMaxWidth + 'px');
      
      $item.find('a').click(function(evt) {
        evt.stopPropagation();
      });
      
      $item.on('keypress', function(evt) {
        if(evt.keyCode === 13 || evt.keyCode === 32) {
          $(this).trigger('click');
        }
      });
      
      $item.on('mouseenter',function() {
        var $this = $(this);
        $this.siblings().removeClass('is-active');
        $this.siblings().css('width', itemMinWidth + 'px');
        $this.addClass('is-active');
        $this.css('width', itemMaxWidth + 'px');
      });
      
      $item.on('mouseleave',function() {
        var $this = $(this);
        $this.siblings().removeClass('is-active');
        $this.siblings().css('width', itemMinWidth + 'px');
        $this.removeClass('is-active');
        $this.css('width', itemMinWidth + 'px');
      });
      
      $item.on('click ',function() {
        var $this = $(this);
        $this.siblings().removeClass('is-active');
        $this.siblings().css('width', itemMinWidth + 'px');
        $this.toggleClass('is-active');
        if ($this.hasClass('is-active')) {
           $this.css('width', itemMaxWidth + 'px');
        } else {
          $this.css('width', itemMinWidth + 'px');
        }
      });
      
      var $itemInner = $item.find('.js-horizontal-collapse-item-inner');
      $itemInner.css('width', itemMaxWidth + 'px');
    });
  });
});

              
            
!
999px

Console