Reputation: 363
I have a table with two columns, first column 65%, second 35%. It perfectly fits to 100% of screen, if first column has enough text in it to fill that 65%, but if it is empty (or small amount of text) - then first column shrinks and second expands.
How can I make first column ALWAYS 65% of screen, with or without text?
Upvotes: 3
Views: 4192
Reputation: 1063
try this css :
.table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
.td1 {
border: 1px solid #000;
width: 65%;
}
.td2{border: 1px solid #000;
width: 35%;
}
and
<table class="table">
<tr>
<td class="td1">data</td>
<td class="td2">data</td>
</tr>
</table>
Upvotes: 0
Reputation: 16685
Try adding this CSS:
table {
table-layout: fixed;
empty-cells: show;
}
https://developer.mozilla.org/en-US/docs/CSS/empty-cells
https://developer.mozilla.org/en-US/docs/CSS/table-layout
@kalpesh's recommendation for <colgroup>
is a good one too.
https://developer.mozilla.org/en-US/docs/HTML/Element/colgroup
Upvotes: 0
Reputation: 2822
Try this:
<table class="fixed_width">
<col width="65%" />
<col width="35%" />
<tr>
<td>your data</td>
<td>your data</td>
</tr>
</table>
And CSS:
table.fixed_width { table-layout:fixed; }
table.fixed_width td { overflow: hidden; }
Upvotes: 2
Reputation: 2100
<table>
<tr>
<td style="width: 65%;">
first column
</td>
<td style="width: 35%;">
second column
</td>
</tr>
</table>
The first column will always stay 65% unless, you put something inside that is larger then 65% (a large picture for example)
Upvotes: 0