I'm buindling a custom table with a detached header. That means the table rows content can be scrolled while the table header remain visible.
I'm almost there, except for 2 minor things I need to accomplish.
Problem 1: I need to keep my vertical bar visible at all time, but when I have more columns than the width, the horizontal scrollbar appears and send my vertical bar to the right side of the columns, making it disappear:
Problem 2: I need to be able to extend the last column to fill the whole width, even if there is space left:
I would rather use pure JavaScript, not jQuery.
<p>
Problem 1: How to keep the vertical scrollbar on view
</p>
<div class="container1">
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
<th>Column 7</th>
<th>Column 8</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
<td>Data 7</td>
<td>Data 8</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
<td>Data 7</td>
<td>Data 8</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
<td>Data 7</td>
<td>Data 8</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
<td>Data 7</td>
<td>Data 8</td>
</tr>
</tbody>
</table>
</div>
<p>
Problem 2: How to make the last cell go full width
</p>
<div class="container2">
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
</tr>
</tbody>
</table>
</div>
.container1 table,
.container1 th,
.container1 td {
background-color: white;
padding: 5px;
font-size: 15px;
border: 1px solid black;
border-collapse: collapse;
min-width: 50px;
max-width: 50px;
}
.container1 {
max-width: 100%;
width: 100%;
overflow-x: scroll;
}
.container1 table tbody,
.container1 table thead {
display: block;
}
.container1 table tbody {
overflow-y: scroll;
height: 50px;
}
.container2 table,
.container2 th,
.container2 td {
background-color: white;
padding: 5px;
font-size: 15px;
border: 1px solid black;
border-collapse: collapse;
min-width: 50px;
max-width: 50px;
}
.container2 th:last-child,
.container2 td:last-child {
background-color: yellow;
min-width: 50px;
max-width: 100%;
}
.container2 {
max-width: 100%;
width: 100%;
overflow-x: scroll;
}
.container2 table tbody,
.container2 table thead {
display: block;
}
.container2 table tbody {
overflow-y: scroll;
height: 50px;
}