cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              
<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>
            
          
!
            
              /* =============================================================================
   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;
  }
  
}
            
          
!
            
              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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console