html - Cross-browser compatible scrollable table -


i trying make table takes 50% of screen. however, if there more info table can hold, should scrollable. have been trying many different ways this, none have found worked. needs cross-browser compatible modern browsers , preferably older browsers to. how can this? in advance! note: using w3.css code have tried:

table {    height: 100px;    overflow-y: scroll;  }
<table class="w3-table-all">  <thead>    <tr class="w3-red">      <th>first name</th>      <th>last name</th>      <th>points</th>    </tr>  </thead>  <tbody>    <tr>      <td>jill</td>      <td>smith</td>      <td>50</td>    </tr>    <tr>      <td>eve</td>      <td>jackson</td>      <td>94</td>    </tr>    <tr>      <td>adam</td>      <td>johnson</td>      <td>67</td>    </tr>  </tbody>  </table>

i have tried doing still doesn't work. tried various combinations thereof, styling tbody, tr, td, etc. none showed scrollbar

first put table inside div put specified height , overflow class of div become scrollable.

css

.table-scroll {   border: 1px solid #000;   width:50%;   height: 100px;   overflow-y: scroll; } 

html

<div class="table-scroll"> <table class="w3-table-all"> <thead>   <tr class="w3-red">     <th>first name</th>     <th>last name</th>     <th>points</th>   </tr> </thead> <tbody> <tr>   <td>jill</td>   <td>smith</td>   <td>50</td> </tr> <tr>   <td>eve</td>   <td>jackson</td>   <td>94</td> </tr> <tr>   <td>adam</td>   <td>johnson</td>   <td>67</td> </tr> </tbody> </table> </div> 

here reference in jsfiddle.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -