tags:

views:

1074

answers:

4

Please consider the following:

<td style="width: 500px;">
    <div style="width: 400px;">SomeContent</div>
</td>

For some reason, the column that contains a div will not expand to 500px as the style suggests.

Do you know how to get the td to honor the width that I am specifying in the style?

+2  A: 

In theory, you can use the min-width and max-width styles. In practice, some popular browsers ignore these styles. In this case you have explicitly declared a width of 400, so it should always equal 400 unless acted upon by a child growing or a parent shrinking. You could runat-"server" and programatically determine the width attribute based on content size, or you could play with the overflow style, or put it in a Panel with a horizontal scrollbar.

tsilb
The min-width attribute is what did the trick. Thanks!!
Steve Horn
A: 

is there a width on the table and other tds within the table? Also, have you got a doc type going on?

However, that said, here's your solution:

<td style="width: 500px">
  <div style="padding: 0 50px">SomeContent</div>
</td>

Setting your padding appropriately.


Having reread your question, I feel that this might not be the answer you're looking for. Could you elaborate a little more?

Steve Perks
A: 

try this:

<td style="width:500px;">
  <div style="width:100%;">SomeContent</div>
</td>

if however you want the td to be the exact size of the div, to a MAX of 500px, then try:

<td style="max-width:500px;">
  <div style="width:100%;">SomeContent</div>
</td>

Keeping in mind that IE6 doesn't understand max-width, and will just force it to be 500px.

scunliffe
A: 

You have no reason to set a fixed width on the DIV within the TD, by default DIV's are block elements which means they will fill the full width of there containing element.

Either set padding on the TD or margin on the DIV to achieve the same style.

Without seeing futher markup or css i can't see any reason why the TD would not be 500px, if you added two different background colors to the elements you will indeed noticed that the TD will be 100px wider than the div.

Phunky