Darryl Hein Darryl Hein - 3 months ago 22
CSS Question

How do you control the minimum width of a table cell?

I have a need in a variety of cases to ensure a table cells don't shrink past a certain width. To accomplish this I've tried a number of options with varying results. Some of the options I've tried:

  • width on the td: works alright, but some browsers ignore it and it's not valid in HTML5

  • CSS width inside
    or stylesheet: ignored by some browsers

  • image with width=X and height=1: causes the content of the td to be push up or down (by more than 1px).

  • div with width=X and height=1 and float:left: this seems to work the best at the moment, although it does push the content up or down slightly

Any other ideas?

I need to it work in anything, including IE6 :( but if there are solutions that don't work in IE6, but everything else, that'd be a start anyway :)


You can't reliably control the width of a table cell. It's best to wrap the contents in a DIV (or any other block level elements) and target that element.