html - How to make my table collapse by row in mobile view -


i'm trying add responsive table iframe in website. table looks in desktop not in mobile view. have tried @media make table collapse row first cell of each row become vertically aligned in 1 column.

|-------------------------------------------------| |    row head1      | data1 |              data2  | |-------------------------------------------------| <--my table  |    row head2      | data3 |              data4  |   |--------------------| |    row head1       |    <- want have in mobile view |--------------------| |    data1           | |--------------------| |    data2           | |--------------------| |    row head2       | |--------------------| |    data3           | |--------------------| |    data4           | |--------------------| 

anything did wrong in following?

<style type="text/css">  .tg  {border-collapse:collapse;border-spacing:0;border-color:#ffffff;}  .tg td{font-family:arial, sans-serif;font-size:14px;padding:10px 10px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ffffff;}  .tg th{font-family:arial, sans-serif;font-size:14px;font-weight:normal;padding:0px 0px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ffffff;}  .tg .tg-iwtr{background-color:#34cdf9;color:#ffffff;vertical-align:top;}  .tg .tg-yzt1{background-color:#efefef;vertical-align:top}  .tg .tg-cxkv{background-color:#ffffff}  .tg .tg-bsv2{background-color:#efefef}  .tg .tg-3we0{background-color:#ffffff;vertical-align:top}  .tg .tg-yw4l{vertical-align:top}  @media , (max-width: 479px) {    table,    thead,    tbody,    th,    td,    tr {      display: block	;    	  	    }  </style>
<div class="tg-wrap"><table class="tg" style="width: 100%;" >  <colgroup>  <col style="width: 110px">  <col style="width: 108px">  <col style="width: 418px">  <col style="width: 578px">  </colgroup>    <tr>      <td class="tg-iwtr" rowspan="2">04/08/2017</th>      <td class="tg-bsv2">11:00 – 12:30</th>      <td class="tg-bsv2">data</th>      <td class="tg-yzt1">data</th>    </tr>    <tr>      <td class="tg-cxkv">15:00 – 17:00</td>      <td class="tg-cxkv">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-iwtr">05/08/2017</td>      <td class="tg-yzt1">11:00 – 12:30</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>    <tr>      <td class="tg-iwtr" rowspan="2">06/08/2017</td>      <td class="tg-3we0">15:00 – 16:30</td>      <td class="tg-3we0">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-yzt1">16:30 – 18:00</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>    <tr>      <td class="tg-iwtr" rowspan="2">07/08/2017</td>      <td class="tg-3we0">15:00 – 16:30</td>      <td class="tg-3we0">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-yzt1">16:30 – 18:00</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>  </table></div>

the css looks fine me. note in html you're opening <td> closing </th>.

<style type="text/css">  .tg  {border-collapse:collapse;border-spacing:0;border-color:#ffffff;}  .tg td{font-family:arial, sans-serif;font-size:14px;padding:10px 10px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ffffff;}  .tg th{font-family:arial, sans-serif;font-size:14px;font-weight:normal;padding:0px 0px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ffffff;}  .tg .tg-iwtr{background-color:#34cdf9;color:#ffffff;vertical-align:top;}  .tg .tg-yzt1{background-color:#efefef;vertical-align:top}  .tg .tg-cxkv{background-color:#ffffff}  .tg .tg-bsv2{background-color:#efefef}  .tg .tg-3we0{background-color:#ffffff;vertical-align:top}  .tg .tg-yw4l{vertical-align:top}  @media , (max-width: 479px) {    table,    thead,    tbody,    th,    td,    tr {      display: block	;    	  	    }  </style>
<div class="tg-wrap"><table class="tg" style="width: 100%;" >  <colgroup>  <col style="width: 110px">  <col style="width: 108px">  <col style="width: 418px">  <col style="width: 578px">  </colgroup>    <tr>      <th class="tg-iwtr" rowspan="2">04/08/2017</th>      <th class="tg-bsv2">11:00 – 12:30</th>      <th class="tg-bsv2">data</th>      <th class="tg-yzt1">data</th>    </tr>    <tr>      <td class="tg-cxkv">15:00 – 17:00</td>      <td class="tg-cxkv">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-iwtr">05/08/2017</td>      <td class="tg-yzt1">11:00 – 12:30</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>    <tr>      <td class="tg-iwtr" rowspan="2">06/08/2017</td>      <td class="tg-3we0">15:00 – 16:30</td>      <td class="tg-3we0">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-yzt1">16:30 – 18:00</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>    <tr>      <td class="tg-iwtr" rowspan="2">07/08/2017</td>      <td class="tg-3we0">15:00 – 16:30</td>      <td class="tg-3we0">data</td>      <td class="tg-3we0">data</td>    </tr>    <tr>      <td class="tg-yzt1">16:30 – 18:00</td>      <td class="tg-yzt1">data</td>      <td class="tg-yzt1">data</td>    </tr>  </table></div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -