I have a table which can be scrolled horizontally. I have fixed the first column, so that it stays in place while rest of the columns are scrolled. It is working fine, except first <td>
elements do not have same height as rest of the row.
HTML:
<div>
<table>
<tr><th class="headcol">1</th><td class="long">QWERTYUIOPAS<br />DFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
<tr><th class="headcol">2</th><td class="long">QWERTYUIO<br />PASDFGHJKL<br />ZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
<tr><th class="headcol">3</th><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
<tr><th class="headcol">4</th><td class="long">QWERTYUI<br />OPASDFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
<tr><th class="headcol">5</th><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
<tr><th class="headcol">6</th><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td><td class="long">QWERTYUIOPASDFGHJKLZXCVBNM</td></tr>
</table>
</div>
CSS:
table {
border-collapse: separate;
border-spacing: 0;
border-top: 1px solid grey;
}
td, th {
margin: 0;
border: 1px solid grey;
white-space: nowrap;
border-top-width: 0px;
}
div {
width: 500px;
overflow-x: scroll;
margin-left: 5em;
overflow-y: visible;
padding: 0;
}
.headcol {
position: absolute;
width: 5em;
left: 0;
top: auto;
border-top-width: 1px;
/*only relevant for first row*/
margin-top: -1px;
/*compensate for top border*/
}
.headcol:before {
content: 'Row ';
}
.long {
background: yellow;
letter-spacing: 1em;
}
Here is jsfiddle: jsfiddle.net/cgg97cmr/
If you check the jsfiddle, you will see that <td>
elements in first column do not adjust their height according to rest of the row. I want them to act like normal <td>
belonging to their respective rows.
`? If so you can do 2 things: set a default height for al the collums to be the same heigt(CSS). Or you can use jquery to read the heigt and then adjust your collum to that height – Scorpion Code Jun 13 '17 at 08:17