Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing HTML table structure based on screen dimensions

Suppose I have a 3x2 HMTL table:

 <table>
  <tr>
    <td> <div id="content1"></div> </td>
    <td> <div id="content2"></div> </td>
    <td> <div id="content3"></div> </td>
  </tr>
  <tr>
    <td> <div id="content4"></div> </td>
    <td> <div id="content5"></div> </td>
    <td> <div id="content6"></div> </td>
  </tr>
 </table>

This is fine when the screen is in landscape mode (ie - width > height)

Suppose height > width, is there a way of dynamically changing the table to the following 2x3 table:

 <table>
  <tr>
    <td> <div id="content1"></div> </td>
    <td> <div id="content2"></div> </td>
  </tr>
  <tr>
    <td> <div id="content3"></div> </td>
    <td> <div id="content4"></div> </td>
  </tr>
  <tr>
    <td> <div id="content5"></div> </td>
    <td> <div id="content6"></div> </td>
  </tr>
 </table>
like image 329
Greg Peckory Avatar asked May 28 '26 03:05

Greg Peckory


1 Answers

<table>
<tr>
 <td>Lorem ipsum</td>
 <td>Lorem ipsum</td>
 <td>Lorem ipsum</td>
</tr>
<tr>
 <td>Lorem ipsum</td>
 <td>Lorem ipsum</td>
 <td>Lorem ipsum</td>
</tr>

table {
 display:flex;
 flex-wrap:wrap;
 width:90%;
 margin:0 auto;
}

tr {
 flex:1 0 300px;
 display:inline;
}

td {
 display:inline-block;
 width:100px;
 height:100px;
}

https://jsfiddle.net/cmckay/02tvkyj8/

http://autoprefixer.github.io/

like image 141
Carol McKay Avatar answered May 30 '26 16:05

Carol McKay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!