I have a code pen here - Code
It's a table in a container, the table is bigger than the container.
When scrolling left to right the table and the headers move
When scrolling up and down I need the header to be sticky and the content to move underneath.
It sort of works here - Code
but I lose the widths of the columns and the table.
How do I make the headers sticky but keep the width of the table
body{
background: grey;
font-family: sans-serif;
}
.page{
background: white;
width: 1200px;
margin: 0 auto;
}
.table-con{
overflow: scroll;
max-width: 1200px;
height: 500px;
}
table{
/*table-layout: fixed;*/
border-collapse: collapse;
width: 1500px;
}
thead th:first-child{
width: 20px;
padding: 0;
}
thead th{
text-align: left;
}
thead tr{
border-bottom: 1px solid #444;
}
tbody td{
border-bottom: 1px solid #aaa;
}
tbody tr:nth-child(even) td:not(:first-child){
background: yellow;
}
tbody td:first-child{
background: none;
border: none;
padding: 0;
}
th, td{
padding: 10px 5px;
&:first-of-type{
padding-left: 20px;
}
&:last-of-type{
padding-right: 20px;
}
}