How to set dynamically the width of a html table column according to its text content?
If you want the width of your td
to change dynamically according to your text, then you shouldn't give any predefined width for the td
element.
In this example, you can see that the first td
has a long text, So all td
's within the same column will have their width set according to the longest td
in the same column.
In the end, it boils down to the user experience. Would the user prefer td
's with varying widths or would the user prefer td
's with equal dimensions where a tool-tip would show the complete text in case it's larger in length than the width of the td
. That, my friend, is a choice you'll have to make :)