I'm trying to make a table where the apad doesn't scroll, but yours does. I use percentages and a fixed width to determine how large each cell is, I want my percentage td to be the same size and aligned with thead headers.
I also have a JSFiddle to show the problem.
.main-wrapper {
overflow-y: scroll;
height: 300px;
border: 1px solid blue;
}
.content-wrapper {
height: 500px;
}
.table {
width: 100%;
table-layout: fixed;
}
.table.content {
margin-bottom: 15px;
}
.header {
position: fixed;
}
.cell {
border: 1px solid red;
width: 100%;
height: 15px;
}
.medium {
width: 100px;
}
.small {
width: 50px;
}
<div class="main-wrapper">
<div class="content-wrapper">
<table class="table header">
<thead>
<tr>
<th class="cell medium">A</th>
<th class="cell small">B</th>
<th class="cell">C</th>
<th class="cell">D</th>
<th class="cell">E</th>
<th class="cell">F</th>
<th class="cell">G</th>
<th class="cell">H</th>
<th class="cell">I</th>
<th class="cell small">J</th>
</tr>
</thead>
</table>
<table class="table content">
<tbody>
<tr>
<td class="cell medium">A</td>
<td class="cell small">B</td>
<td class="cell">C</td>
<td class="cell">D</td>
<td class="cell">E</td>
<td class="cell">F</td>
<td class="cell">G</td>
<td class="cell">H</td>
<td class="cell">I</td>
<td class="cell small">J</td>
</tr>
<tr>
<td class="cell medium">A</td>
<td class="cell small">B</td>
<td class="cell">C</td>
<td class="cell">D</td>
<td class="cell">E</td>
<td class="cell">F</td>
<td class="cell">G</td>
<td class="cell">H</td>
<td class="cell">I</td>
<td class="cell small">J</td>
</tr>
<tr>
<td class="cell medium">A</td>
<td class="cell small">B</td>
<td class="cell">C</td>
<td class="cell">D</td>
<td class="cell">E</td>
<td class="cell">F</td>
<td class="cell">G</td>
<td class="cell">H</td>
<td class="cell">I</td>
<td class="cell small">J</td>
</tr>
<tr>
<td class="cell medium">A</td>
<td class="cell small">B</td>
<td class="cell">C</td>
<td class="cell">D</td>
<td class="cell">E</td>
<td class="cell">F</td>
<td class="cell">G</td>
<td class="cell">H</td>
<td class="cell">I</td>
<td class="cell small">J</td>
</tr>
</tbody>
</table>
</div>
</div>
Run codeHide resultIf I delete position: fixed
, it works the way I want, but the thread does not stay at the top.
source
share