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

              
                <h2>Collapse to Accordions</h2>
<div class="Rtable Rtable--4cols Rtable--collapse js-RtableAccordions">
  
  <button class="Accordion" role="tab" aria-selected="true">Ned</button>
  <div class="Rtable-cell  Rtable-cell--head"><h3>Eddard Stark</h3></div>
  <div class="Rtable-cell">Has a sword named Ice</div>
  <div class="Rtable-cell">No direwolf</div>
  <div class="Rtable-cell  Rtable-cell--foot"><strong>Lord of Winterfell</strong></div>
  
  <button class="Accordion" role="tab" aria-selected="false">Jon</button>
  <div class="Rtable-cell  Rtable-cell--head"><h3>Jon Snow</h3></div>
  <div class="Rtable-cell">Has a sword named Longclaw</div>
  <div class="Rtable-cell">Direwolf: Ghost</div>
  <div class="Rtable-cell  Rtable-cell--foot"><strong>Knows nothing</strong></div>
  
  <button class="Accordion" role="tab" aria-selected="false">Arya</button>
  <div class="Rtable-cell  Rtable-cell--head"><h3>Arya Stark</h3></div>
  <div class="Rtable-cell">Has a sword named Needle</div>
  <div class="Rtable-cell">Direwolf: Nymeria</div>
  <div class="Rtable-cell  Rtable-cell--foot"><strong>No one</strong></div>

</div>


              
            
!

CSS

              
                @media all and (max-width: @breakpoint) { 
  .hiddenSmall {display: none; }
}


/* Tab Styling
==================================== */
@tabColour: darkcyan;

.Tablist {
  display: flex;
  flex-direction: row;
  margin-left: -@bw;
  @media all and (min-width: @breakpoint) { display: none; }
}
.Tab {
  padding: 0.6em 1em;
  margin: 0 @bw @bw 0;
  text-align: center;
  background-color: @tabColour;
  border: solid @bw @tabColour;
  border-bottom-width: 0;
  border-radius: 0.5em 0.5em 0 0;
  font-weight: bold;
  color: darken(@tabColour,20%);
  text-decoration: none;
  transition: background-color 0.1s;
  cursor: pointer;
  &:hover, &:focus {
    background-color: mix(white,@tabColour,10%);
    border-color: mix(white,@tabColour,10%);
    outline: none;
  }
  &[aria-selected="false"]:active {
    margin-top: 0.2em;
    padding-bottom: 0.4em;
  }
  &[aria-selected="true"] {
    background: mix(white,@tabColour,90%);
    cursor: default;
  }
}


/* Accordion Styling
==================================== */
@accordionColour: darkcyan;
@iconSize: 2em;

.Accordion {
  position: relative; top: -@bw; left: -@bw; //compensate for border offset
  width: 100%;
  margin: 0 0 0.5em 0;
  padding: 0.6em 0.6em 0.6em (@iconSize);
  border-radius: 0.5em;
  text-align: left;
  border: solid @bw mix(black,@accordionColour,15%);
  background-color: @accordionColour;
  font-weight: bold;
  color: darken(@accordionColour,20%);
  text-decoration: none;
  transition: background-color 0.1s;
  cursor: pointer;
  @media all and (min-width: @breakpoint) { display: none; }
  &:hover, &:focus {
    outline: none;
    filter: contrast(150%);
  }
  &[aria-selected="true"] {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-width: 0;
    background: mix(white,@accordionColour,70%);
  }
  &:before {
    content: "+";
    position: absolute;
    top: 50%;
    left: 0.3em;
    margin-top: -(@iconSize/1.75);
    font-weight: normal;
    font-size: @iconSize;
    line-height: @iconSize;
    background-size: @iconSize @iconSize;
  }
  &[aria-selected="true"]:before {
    content: "-";
  }
}

.js-RtableTabs, .js-RtableAccordions {
  min-width: 240px;
}
              
            
!

JS

              
                (function ($) {
  "use strict";
  $.fn.responsiveTable = function() { 

    var toggleColumns = function($table) {
      var selectedControls = [];
      $table.find(".Accordion, .Tab").each( function() {
        selectedControls.push( $(this).attr("aria-selected") );
      });
      var cellCount = 0, colCount = 0;
      var setNum = $table.find(".Rtable-cell").length / Math.max( $table.find(".Tab").length, $table.find(".Accordion").length );
      $table.find(".Rtable-cell").each( function() {
        $(this).addClass("hiddenSmall");
        if( selectedControls[colCount] === "true" ) $(this).removeClass("hiddenSmall");
        cellCount++;
        if( cellCount % setNum === 0 ) colCount++; 
      });
    };
    $(this).each(function(){ toggleColumns($(this)); });

    $(this).find(".Tab").click( function() {
      $(this).attr("aria-selected","true").siblings().attr("aria-selected","false");
      toggleColumns( $(this).parents(".Rtable") );
    });

    $(this).find(".Accordion").click( function() {
      $(this).attr("aria-selected", $(this).attr("aria-selected") !== "true" );
      toggleColumns( $(this).parents(".Rtable") );
    });

  };
}(jQuery));


$(".js-RtableTabs, .js-RtableAccordions").responsiveTable();
              
            
!
999px

Console