I want a table with first(and even sometimes second) column (including all the rows so both th and td) to be fixed. Also the last column of the table should be fixed.
The columns in between should (if there are too many columns to fit the screen) be scrollable horizontally. I am having big troubling achieving this.
I can't get the center area to actually scroll unless I set a fixed with or remove the fixed last column but I really need that. Html:
<div class="table-wrapper">
<div class="container">
<table>
<thead>
<tr>
<th></th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>Assets</td>
<td>358 125</td>
<td>716 250</td>
<td>1 074 375</td>
<td>358 125</td>
<td>716 250</td>
<td>1 074 375</td>
<td>358 125</td>
<td>716 250</td>
<td>1 074 375</td>
<td>358 125</td>
<td>716 250</td>
<td>1 074 375</td>
<td>8 595 000</td>
</tr>
<tr>
<td>Some type of assets</td>
<td>179 535</td>
<td>359 070</td>
<td>538 605</td>
<td>179 535</td>
<td>359 070</td>
<td>538 605</td>
<td>179 535</td>
<td>359 070</td>
<td>538 605</td>
<td>179 535</td>
<td>359 070</td>
<td>538 605</td>
<td>4 308 840</td>
</tr>
<tr>
<td>Some other type of assets</td>
<td>134 780</td>
<td>269 560</td>
<td>404 340</td>
<td>134 780</td>
<td>269 560</td>
<td>404 340</td>
<td>134 780</td>
<td>269 560</td>
<td>404 340</td>
<td>134 780</td>
<td>269 560</td>
<td>404 340</td>
<td>3 234 720</td>
</tr>
<tr>
<td>45456 Cars</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>1 078 680</td>
</tr>
<tr>
<td>879878 computers</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>44 945</td>
<td>89 890</td>
<td>134 835</td>
<td>1 078 680</td>
</tr>
</tbody>
</table>
</div></div>
And css:
* {
box-sizing: border-box;
}
.table-wrapper {
position:relative;
float: left;
margin-right: 200px;
}
.container {
overflow-x:scroll;
overflow-y:visible;
margin-left: 200px;
}
td, th {
padding: 5px 20px;
width: 100px;
}
th:first-child, td:first-child {
position: absolute;
left: 5px;
width: 200px;
}
th:last-child, td:last-child {
position: absolute;
right: -200px;
width: 200px;
}
Update: To further explain what I need. The middle part can not be set to fixed with. I want to use as much space of the page as possible. This means if there are only a few columns on a big screen no scrolling would be necessary.