0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1543784
  • 271
  • 2
  • 4
  • 19
  • Correct me if I don't understand the question right. You want all the collums the same heigt, with the current `
    `? 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
  • I see, i implemented a function with jquery but it can only be used with a `static` or `relative` postition. Hold on while I look for something else – Scorpion Code Jun 13 '17 at 08:27
  • see this.https://stackoverflow.com/a/19739775/7951293 – Nithin Charly Jun 13 '17 at 08:35
  • It's not clear what you're asking for. – evilReiko Jun 13 '17 at 08:45

0 Answers0