Reputation: 50732
I have a <table>
with 3 columns as:
table {
border: 1px dashed goldenrod;
}
td {
border: 1px solid gray;
}
<table>
<tr>
<td width="120">Some content</td>
<td width="150">Some content</td>
<td width="100%">Some content</td>
</tr>
</table>
Now the 3rd column ise set to occupy the remaining width..But in my case, while it does stretch and occupy remaining width, it squeezes the first 2 columns...
If I do not give any width to the 3rd column/td, I am able to see the specified width for the first 2 columns..
Please help me.
The table has already been set with width="100%"
Upvotes: 1
Views: 2197
Reputation: 29166
When you are specifying the width of the third td
as 100%
, it implies that its width should be the same as its parent, which is the corresponding tr
in this case. That's why the first and the second td
s are being squeezed as the third td
is trying to occupy the entire row-width.
If there is absolutely no content in the first two td
s, then you won't be able to even see them. Since there are some content in those td
s, browser is allocating as minimum space as possible to those two, and the rest of the width is hogged by the third div.
See a demo on jsfiddle about what happens when the width of the last td
is 50%
. You will see that it occupies exactly half of the row-width.
To remedy this situation, specify a percentage width for the first two td
s, then leave the third one's width blank. Here is a demo which shows this approach.
Upvotes: 1
Reputation: 12541
I would suggest NOT mixing percentages and pixels. This will cause cross-browser issues etc.
You have to decide to go with % or pixels, and then just leave the 3rd column width blank.
Upvotes: 1
Reputation: 616
Leave the last column without width, and set table width to 100% or desired table width.
Upvotes: 4