responsive design - How to fold table columns into rows on mobile devices? -
i'm developing website featuring restaurant's menu. each item available in different sizes, each @ different price. displayed on medium , large devices using table, column each price:
on mobile devices, screen narrow display 4 different sizes per product.
so fold columns rows, having each row starting column name:
is there possible using responsive design? i'm trying avoid maintaining 2 different html versions of content, 1 visible on mobile, , 1 visible on larger screens.
i'm using foundation 5, i'm ideally looking solution using grid system, i'm open solution really.
i found solution on blog: 10+ solutions responsive data table.
it involves making table cells display: block
on mobile devices, , adding data-*
attribute each cell, matching column name.
this data attribute injected in cell's ::before
pseudo-element content: attr()
.
example:
<table> <thead> <tr> <th>pasta</th> <th>small</th> <th>regular</th> </tr> </thead> <tbody> <tr> <td>spaghetti bolognese</td> <td data-th="small">£5.00</td> <td data-th="regular">£7.00</td> </tr> <tr> <td>lasagna</td> <td data-th="small">£5.00</td> <td data-th="regular">£7.00</td> </tr> </tbody> </table>
css:
@media screen , (max-width: 40em) { thead th:not(:first-child) { display: none; } td, th { display: block; } td[data-th]:before { content: attr(data-th); } }
you'll need add float
make pretty.
working example: http://codepen.io/anon/pen/medrzo
Comments
Post a Comment