1

I have a table within a div that is absolutely positioned on my page. Something like (left: 50px; right: 50px; etc).

The first column values can be quite lengthy, but the rest are pretty much a static width. I would like to set the second, third, etc columns to a specific width and have the first column automatically resize. However, I want it to resize even if it would truncate the text (ie I always want the other columns to show). Currently this doesn't happen. It pushes the right columns out of the div.

Here is a fiddle: http://jsfiddle.net/pdtLoy6d/2/ You can reproduce by resizing the right fiddle pane.

<table>
    <col width="auto" />
    <col width="80px" />
    <col width="150px" />
    <tr>
        <td>This is a thing it could be a really really really long string and I want it to truncate</td>
        <td>Thing2</td>
        <td>That thing is always short</td>
    </tr>
    <tr>
        <td>Not sure if it matters, but these rows are all dynamically generated</td>
        <td>Thing2</td>
        <td>test</td>
    </tr>
</table>
table {
    width: 100%;
    border: 1px solid gray;
    border-collapse: collapse;
}
td { 
    border: 1px solid gray;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
THE JOATMON
  • 16,761
  • 34
  • 110
  • 200

1 Answers1

2

Is this what you're looking for?

http://jsfiddle.net/pdtLoy6d/3/

table {
    table-layout: fixed; /*added*/
}
Stickers
  • 70,124
  • 20
  • 133
  • 171