fieke
11/12/2013 - 3:13 PM

responsive tables

responsive tables

table {
      border: 0px solid #ccc;
      width: 100%;
    }

    thead {
      display: none;
    }

    thead, tbody {
      float: left;
      width: 100%;
    }

    td, th {
      display: block;
      width: 100%;
      height: 30px;
      text-align: center;
      border: 1px solid #ddd;
      border-bottom: 0px;
      /*width: 100%;*/
      float: left;
      clear: both;
    }

    td:before {
      content: attr(data-label) ": ";
    }

    tr {
      width: 100%;
      display: block;
      float: left;
      margin-bottom: 20px;
      border-bottom: 1px solid #ddd;
    }

    @media screen and (min-width: 526px) {
      table {
        width: auto;
      }
      thead, tbody {
        width: auto;
        display: block;
      }
      tr {
        width: 100px;
      }
      td, th {
        width: 100px;
        clear: both;
      }

      td:before {
        content: "";
      }
    }
(function($) {
  $('thead').each(function() {
    $th = $(this).find('th')
    $(this).next('tbody').find('tr').each(function(tr) {
      for(var i = 0; i < $th.length; i++) {
       $(this).find('th, td').eq(i).attr('data-label', $th.eq(i).text());
      }
    });
  });
})(jQuery);