I have a table with four column, where the first column is a nested structure which may have (n) number of nesting and text length may be higher, I want to add horizontal scroll bar only for the first column of the table so that I can see the nesting structure.
I have tried the below code but not able to achieve horizontal scroll bar for the first column of the table.
I need a table with horizontal scroll bar only for the first column Name I have added a sample code which I have tried:
.table {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
border: 1px solid grey;
}
.wrapper {
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 1px;
width: 700px;
}
td, th {
border: 1px solid grey;
}
.indent {
display: inline-block;
width: 35px;
height: 10px;
}
.table tr th:first-child,
.table tr td:first-child {
width: 400px;
}
<!DOCTYPE html>
<html>
<head>
<body>
<div class='wrapper'>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Level 1</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"></span>
<span> Level 1.1 </span>
</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"> </span>
<span class="indent"> </span>
<span>Sub level 1.1.2</span>
</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"> </span>
<span class="indent"> </span>
<span class="indent"> </span>
<span> Sub Level 1.2.3</span></td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span>Level 2 </span></td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"> </span>
<span>Level 2.1 </span></td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"> </span>
<span class="indent"> </span>
<span>Level 2.1.2 </span></td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"> </span>
<span class="indent"> </span>
<span class="indent"> </span>
<span>Level 2.1.3 </span></td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>
<span class="indent"></span>
<span class="indent"></span>
<span class="indent"></span>
<span class="indent"></span>
<span>Level 2.1.4 </span>
</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>