Column widths to auto adjust for text?

Is there any way to make columns in a table auto adjust width-wise, to the width of the longest text in a cell in that column please? and so correspondingly, also have the table auto adjust at the same time.

Can you give us your example? I’m having trouble visualizing what makes this differ from default table behavior.

If the text is non wrapping text then you set the cell to width:1px and use white-space:nowrap. The text in that column will then determine the width of the cell.

table{table-layout:fixed;}
td{width:1px;white-space:nowrap;}

It’s a technique commonly used for images and captions (without the white-space:nowrap) and allows text to wrap at the limits of an image automatically.

However, as Ryan said it might help if we knew a bit more about what you were trying to do :smile:

1 Like

Thanks Paul, you’ve solved the problem straight away.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.