Creating a table with both vertical and horizontal scrolling, along with a fixed header and an auto width for the table is proving to be quite challenging. As a workaround, I'm experimenting with using div elements instead. Below is the code snippet I've come up with: Check out my code here
body {
background: #20262E;
padding: 20px;
color:#fff;
font-family: Helvetica;
}
.tableContainer{
border:1px solid #fff;
}
.tableheader{
font-weight:bold;
border-bottom:1px solid #fff;
position:relative;
}
.tableBody{
max-height:150px;
overflow-y:auto;
padding-top:63px;
}
.tableheader .tablerow{
display:table;
background: red;
width: 100%;
position:absolute;
}
.tableheader .tablerow > div{
padding:5px;
display:table-cell;
border-right:1px solid #fff;
}
.tableBody .tablerow{
display:table;
}
.tableBody .tablerow > div{
padding:5px;
border-right:1px solid #fff;
display:table-cell;
}
<div class="tableContainer">
<div class="tableheader">
<div class="tablerow">
<div>
Lorem ipsum dolor sit amet
</div>
<div>
Suspendisse ipsum diam, sollicitudin a tincidunt ac
</div>
<div>
Lorem ipsum
</div>
<div>
Lorem ipsum dolor sit amet
</div>
<div>
Suspendisse ipsum diam, sollicitudin a tincidunt ac
</div>
<div>
Lorem ipsum
</div>
</div>
</div>
<div class="tableBody">
<div class="tablerow">
<div>
Lorem ipsum dolor sit amet
</div>
<div>
Suspendisse ipsum diam, sollicitudin a tincidunt ac
</div>
.tableContainer{ border:1px solid #fff;
}
.tableheader{
font-weight:bold;
border-bottom:1px solid #fff;
position:relative;
}
.tableBody{
max-height:150px;
overflow-y:auto;
padding-top:63px;
}
.tableheader .tablerow{
display:table;
background: red;
width: 100%;
position:absolute;
}
.tableheader .tablerow > div{
padding:5px;
display:table-cell;
border-right:1px solid #fff;
}
.tableBody .tablerow{
display:table;
}
.tableBody .tablerow > div{
padding:5px;
border-right:1px solid #fff;
display:table-cell;
}
I'm currently struggling with achieving horizontal scrolling and managing column widths.
Alternatively, you can view my other code here. This code also presents challenges with horizontal scrolling.
Your assistance in resolving this issue would be highly appreciated.