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

              
                
<table class="dataTable">
    <thead>
        <tr>
            <th>Numbers</th>
            <th>Names</th>
            <th>Values</th>
            <th>Dates</th>
            <th>Cash Money</th>
            <th>Messages</th>
            <th>Buttons</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><a href="#">000000001</a></td>
            <td>Dr. Jayhawk</td>
            <td>102</td>
            <td>03/30/1940</td>
            <td>$60.42</td>
            <td>PAID</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
        <tr>
            <td><a href="#">000000002</a></td>
            <td>Dr. Jayhawk</td>
            <td>137</td>
            <td>03/18/1953</td>
            <td>$69.68</td>
            <td>PAID</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
        <tr>
            <td><a href="#">000000003</a></td>
            <td>Dr. Wolverine Longer Text Test</td>
            <td>154</td>
            <td>03/29/1976</td>
            <td>$86.68</td>
            <td>PAID</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
        <tr>
            <td><a href="#">000000004</a></td>
            <td>Dr. Tarheel</td>
            <td>113</td>
            <td>03/30/1981</td>
            <td>$63.50</td>
            <td>PAID</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
        <tr>
            <td><a href="#">000000005</a></td>
            <td>Dr. Orange</td>
            <td>147</td>
            <td>03/30/1987</td>
            <td>$74.73</td>
            <td>PAID</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
        <tr>
            <td><a href="#">000000006</a></td>
            <td>Dr. Who</td>
            <td>000</td>
            <td>04/08/2013</td>
            <td>$0.00</td>
            <td>PENDING</td>
            <td>
                <button class="button action">Select</button>
            </td>
        </tr>
    </tbody>
</table>

<div class="container">  
    <section class="pattern-description">
        <h1>Responsive Data Tables</h1>
        <p>A data table that will flip the table headers and rows into columns at small resolutions. The rows (which were previously columns) can then be scrolled through from left to right.</p>
        <p>This particular solution currently does not get along well with IE. The process of flipping the table on its side is just too confusing and IE fails to respect the change of table-cell displays to block displays. When sizing your browser up or down a refresh will be required to properly align and size the table rows.</p>
        <h2>Considerations</h2>
        <ul>
            <li>Very similar to the <a href="http://dbushell.com/demos/tables/rt_05-01-12.html">Horizontal Overflow</a> solution. The primary difference being instead of simply locking the first column, this solution reorders the column headers into a vertical stack along with the data.</li>
        </ul>
    </section>
    <footer role="contentinfo">   
        <div>
            <nav id="menu">
                <a href="https://bradfrost.github.com/this-is-responsive/patterns.html">&larr;More Responsive Patterns</a>
            </nav>
        </div>
    </footer>
</div>
              
            
!

CSS

              
                /* =============================================================================
   Responsive Table CSS
   ========================================================================== */
   
.dataTable {
  display: block;
  width: 100%;
  margin: 1em 0;
}

.dataTable thead, .dataTable tbody, .dataTable thead tr, .dataTable th {
  display: block;
}

.dataTable thead {
  float: left;
}

.dataTable tbody {
  width: auto;
  position: relative;
  overflow-x: auto;
}

.dataTable td, .dataTable th {
  padding: .625em;
  line-height: 1.5em;
  border-bottom: 1px dashed #ccc;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
}

.dataTable th {
  text-align: left;
  background: rgba(0, 0, 0, 0.14);
  border-bottom: 1px dashed #aaa;
}

.dataTable tbody tr {
  display: table-cell;
}

.dataTable tbody td {
  display: block;
}

.dataTable tr:nth-child(odd) {
	background: rgba(0, 0, 0, 0.07);
}

@media screen and (min-width: 50em) {

  .dataTable {
    display: table;
  }
  
  .dataTable thead {
    display: table-header-group;
    float: none;
  }
  
  .dataTable tbody {
    display: table-row-group;
  }
  
  .dataTable thead tr, .dataTable tbody tr {
    display: table-row;
  }
  
  .dataTable th, .dataTable tbody td {
    display: table-cell;
  }
  
  .dataTable td, .dataTable th {
    width: auto;
  }
  
}
              
            
!

JS

              
                var smallBreak = 800; // Your small screen breakpoint in pixels
var columns = $('.dataTable tr').length;
var rows = $('.dataTable th').length;

$(document).ready(shapeTable());
$(window).resize(function() {
    shapeTable();
});

function shapeTable() {
    if ($(window).width() < smallBreak) {
        for (i=0;i < rows; i++) {
            var maxHeight = $('.dataTable th:nth-child(' + i + ')').outerHeight();
            for (j=0; j < columns; j++) {
                if ($('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').outerHeight() > maxHeight) {
                    maxHeight = $('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').outerHeight();
                }
              	if ($('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').prop('scrollHeight') > $('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').outerHeight()) {
                    maxHeight = $('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').prop('scrollHeight');
                }
            }
            for (j=0; j < columns; j++) {
                $('.dataTable tr:nth-child(' + j + ') td:nth-child(' + i + ')').css('height',maxHeight);
                $('.dataTable th:nth-child(' + i + ')').css('height',maxHeight);
            }
        }
    } else {
        $('.dataTable td, .dataTable th').removeAttr('style');
    }
}
              
            
!
999px

Console