0

I want to make a table with two columns. The first one with a text caption and second one with a link. If the link is bigger than available space than I want to overflow with "...". This is what I've tried:

<html>

<style>
    table {
        width: 100px;
        border: dotted;
    }

    td {
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }
</style>

<body>
    <table>
        <tr>
            <td colspan=2>
                First name and last name
            </td>
        </tr>
        <tr>
            <td>
                Info:
            </td>
            <td>
                <a href="google.pl">CLICKKKKKKKKKKKKKKXX</a>
            </td>
        </tr>
    </table>
</body>
</html>

but it doesn't overflow and table gets bigger than 100px. I've tried adding max-width to tr{} but it also doesn't work.

What is the solution for that?

Krzysztof Majewski
  • 2,494
  • 4
  • 27
  • 51

2 Answers2

2

Try this

table{table-layout:fixed;}
Head In Cloud
  • 2,001
  • 1
  • 8
  • 10
2

You want the overflowing text to be wrapped with ... but you haven't mentioned the threshold max-width value to trigger overflow and replace the remaining text with ...

Try this :

td
{
  width: 50px;
  max-width: 75px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Working Example : JsFiddle

Hari Harker
  • 702
  • 1
  • 12
  • 29