Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Break Table Columns (TD) To Multiple Rows On Small Screens

I have a html table:

<table>
<tr> <td>data...</td>  <td>data...</td>  <td>data...</td> </tr>
</table>

This shows as:

-------------------------
|data...|data...|data...|
-------------------------

which is fine on large screens, but what i want is to break the columns into multiple rows as needed if the screen is small.

So when needed the table would show as:

----------
|data....|
|--------|
|data....|
|--------|
|data....|
----------

Is there a way to do this with something like css?

like image 443
Daniel Valland Avatar asked May 16 '16 12:05

Daniel Valland


2 Answers

You can change to display: table-row with media queries Fiddle

@media(max-width: 480px) {
  td {
    display: table-row;
  }
}
<table>
<tr> <td>data...</td>  <td>data...</td>  <td>data...</td> </tr>
</table>
like image 194
Nenad Vracar Avatar answered Sep 28 '22 07:09

Nenad Vracar


You can use display:block as for break the column
@media(max-width: 480px) {
  td {
    display:block;
  }
}
<table>
<tr> <td>data...</td>  <td>data...</td>  <td>data...</td> </tr>
</table>
like image 38
Anubhav pun Avatar answered Sep 28 '22 07:09

Anubhav pun