I was trying to make a horizontally scrolling table and I was able to make it but only the first column is fixed. I need to make the scrolling table for two or more column to be fixed.
Here is the link of the fiddle here
I want to make this table scrolling for two or more than 2 columns be fixed and rest scrolling. Is it possible to make a CSS class (example "fixedColumn") so that any column having this CSS class is fixed and rest of the columns are scrolling? I can not use any JavaScript plugins (no JS at all).
Please help.
HTML
<div class="table-wrapper"> <table id="consumption-data" class="data"> <thead class="header"> <tr> <th>Month</th> <th>Item 1</th> <th>Item 2</th> <th>Item 3</th> <th>Item 4</th> </tr> </thead> <tbody class="results"> <tr> <th>Jan</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>Feb</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>Mar</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>Apr</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>May</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>Jun</th> <td>3163</td> <td>3163</td> <td>3163</td> <td>3163</td> </tr> <tr> <th>...</th> <td>...</td> <td>...</td> <td>...</td> <td>...</td> </tr> </tbody> </table> CSS
.table-wrapper { overflow-x:scroll; overflow-y:visible; width:250px; margin-left: 120px; }
td, th { padding: 5px 20px; width: 100px; } th:first-child { position: absolute; left: 5px; }