tags:

views:

48

answers:

3

How can you enforce the minimum width for a TD that can optionally contain an image? I ask this because I'm using a Javascript chess widget but when there are no pieces in any of the squares of a particular column, regardless of the width style of the td's being set to 36px, this column renders much narrower than those that have at least one row that contains the image of a chess piece.

Note that all the style is being set directly on each td cell. I read somewhere that a possible solution would be to instead create a div inside the td and set the width on that. Am hoping to avoid that as it might require significant modification to the underlying Javascript library. I've tried specifying !important along with the width but it had no effect.

Using firebug I can modify the width attribute but it seems the numbers are incorrect. For instance I can decrease the width all the way to 0 and it still appears the same. Or I can set the width to more than 36 and it appears to grow by width-36, but if for instance I set both the height and width of one of these narrow cells to the same number, lets say 60px, the height of what gets displayed is greater than the width and it appears as a rectangle not a square.

Furthermore not only can the td optionally contain an image, but each square specifies a background image too. So I am at a loss :( Thanks in advance

A: 

You can use the td tags width attribute or you could use css and set the width.

Chris
Wish someone would comment as to why I was down-voted? :-( I'd like to learn.
Chris
+1  A: 

By default tables will auto-size their columns.

If you set the table style to include:

table-layout: fixed;

then you'll have much better control of it via css and attributes.

sje397
+3  A: 

When I alter the CSS in your file using Firebug or the JS inspector in Chrome, setting the min-width property instead of the width property does the trick. Might want to try that? Not sure how IE will like that, though.

BTW: Why not use classes to do the CSS? It's kinda horrible to debug, this way.

kander
Works for me too. And kudos for suggesting classes.
Dan Breslau
As noted this works in FF. Don't care about IE, this will actually run in a custom browser, I've grepped the code base, and it appears it will support min-width. As for why no classes, it's a 3rd party library, so I didn't write it, but anyway it seems the width is supposed to be configurable, which would seem to preclude a class. Anyway, now I have another problem, the line of js code is "td.style.width = this.opts['squareSize'];" but I can't get either "td.style.min-width" or "td.style['min-width']" to work
George Jempty
IE8 seems to want both: `min-width: 36px; width: 36px;` Not sure about other IE versions.
Dan Breslau
I see I should instead be trying td.style.minWidth to set this via Javascript but unfortunately the custom browser's Javascript engine (SEE: "Simple EcmaScript Engine") doesn't seem to support it :(
George Jempty