1

I try to show a scrollbar in my table if the value of the cell is too long, i tried it with overflow but as you can see it does not work, there is no scrollbar, the word is displayed in it's full length

table {
  border: 1px solid black;
}

table td {
  border: 1px solid black;
}

table th {
  border: 1px solid black;
}

.test {
    overflow: scroll;
    color: red;
    max-width: 50px;
}
<table>
<tr>
  <th class="test">Filename</th>
  <th>value</th>
</tr>
<tr>
  <td class="test">Very long filename for demonstration</td>
  <td>Test</td>
</tr>
</table>

UPDATE:

I just noticed that the scrollbars are showing if i am using Chrome Browser, but not if i use Firefox. So unfortunatelly overflow does not seem to be compatible with firefox.

5
  • 2
    check stackoverflow.com/questions/9789723/… or stackoverflow.com/questions/509711/… Commented Feb 3, 2016 at 14:31
  • @LucaGiardina, oh mee too if i am using chrome, i just noticed that it does not work if use firefox Commented Feb 3, 2016 at 14:42
  • 1
    You can use a div within a td. I believe overflow works for div in firefox as shown in this post: stackoverflow.com/questions/16328233/… Commented Feb 3, 2016 at 14:52
  • Could you try using -moz-scrollbars-horizontalinside your .testrule? Should be the mozilla specific 'overflow' option. Commented Feb 5, 2016 at 8:13
  • Nothing happens if i do that. Commented Feb 5, 2016 at 8:22

1 Answer 1

3

If you declare

.test {
display:inline-block;
white-space: nowrap;
overflow-x: scroll;
}

then the overflow:scroll will work in Firefox as well:

table {
  border: 1px solid black;
}

table td {
  border: 1px solid black;
}

table th {
  border: 1px solid black;
}

.test {
  color: red;
  display: inline-block;
  max-width: 50px;
  white-space: nowrap;
  overflow-x: scroll;
}
<table>
<tr>
  <th class="test">Filename</th>
  <th>value</th>
</tr>
<tr>
  <td class="test">Very long filename for demonstration</td>
  <td>Test</td>
</tr>
</table>


Version 2:

Main changes:

  • td has display: block; instead of display: inline-block;
  • td has overflow:auto; instead of overflow:scroll;

table, td {
  border: 1px solid black;
}

td {
  color: red;
  display: block;
  max-width: 120px;
  white-space: nowrap;
  overflow-x: auto;
}
<table>
<tr><td>account_requests</td></tr>
<tr><td>backend.template</td></tr>
<tr><td>firmware.host</td></tr>
<tr><td>frontend.template</td></tr>
<tr><td>license.host</td></tr>
<tr><td>licensing.host</td></tr>
<tr><td>mail.auto_smtp_authentification_password</td></tr>
</table>

Sign up to request clarification or add additional context in comments.

8 Comments

Unfortunatelly this does not work properly as you can see in my screenshot. The scroll bar is showing even though the text is not oversized and the table looks weird. pasteall.org/pic/show.php?id=98793
The setup in the image you link to above and the setup you posted in your original question seem quite different. I have added a Version 2 to the answer above.
Thank you, but this did not really improved it for me, now it looks like this: pasteall.org/pic/show.php?id=98802
Yes. I thought that's exactly what you are aiming for: I try to show a scrollbar in my table if the value of the cell is too long
You are right sorry. But i mean it still looks weird, there are now white gaps between the rows for some unknown reason.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.