3

I would like to limit width of columns in a table.

<!DOCTYPE html>
<style type="text/css">
table tr td {border:1px solid; max-width:2em; overflow:hidden; white-space:nowrap;}
</style>
<table>
    <tr><td>this is looooooooo ooooooooo ooooooooooooo ooooooooo ng text</td></tr>
</table>

The next code works well in Firefox (the cell has a limited width), but width is not limited in IE9.

nagy.zsolt.hun
  • 6,292
  • 12
  • 56
  • 95

2 Answers2

3

You need to add a div after the td like the following in HTML. Nothing within that div will stretch out the table cell.

Demo

<!DOCTYPE html>
    <table>
      <tr>
        <td>
          <div>
            this is looooooooo ooooooooo ooooooooooooo ooooooooo ng text
          </div>
        </td>
      </tr>
    </table>

Css:

table tr td {
    border:1px solid;
    max-width:2em;
    overflow:hidden;
    white-space:nowrap;
}

div {
  width: 2em;
}

Works great in IE8, Chrome and Firefox.

Sri
  • 2,233
  • 4
  • 31
  • 55
-1

Try to use IE expressions width: expression(document.body.clientWidth > 901 ? "900px" : "auto");

ssuperczynski
  • 3,190
  • 3
  • 44
  • 61