How can I limit table column width?

nightcoder picture nightcoder · Sep 14, 2011 · Viewed 92.9k times · Source

One of the columns in my table can contain a long text without whitespaces. How can I limit its width to, say, 150px? I don't want it to be 150px always (if it's empty it should be narrow), but if there is a long text I want it to be limited with 150px and the text to be wrapped.

Here is a test example: http://jsfiddle.net/Kh378/ (let's limit the 3rd column).

Thank you in advance.

Update:
Setting this styles:

word-wrap: break-word;
max-width: 150px;

does not work in IE8 (tested on different computers) and I suppose it does not work in any version of IE.

Answer

Brandon picture Brandon · Sep 14, 2011

Updated

On the table's td and th tags I added:

word-wrap: break-word;
max-width: 150px;

Not fully compatible in every browser but a start.