I have a pretty simple table:
<table cellspacing=0 cellpading=0 border=0>
<tr>
<td width="50%">Here is column 1</td>
<td width="50%">Here is column 2</td>
</tr>
</table>
Is there any way to have column 2 reduce width before column 1 does? I'd like column 1 to stay as close to 50% as possible if the screen width becomes reduced. If there is no further room for column 2 to collapse, however, then it is ok for column 1 to shrink.
I don't want to apply "white-space: nowrap" to column 1, apply a fixed with, or use javascript. Is there any CSS solution?
Take the width of the table and divide it by the number of cell (). If the table dynamically widens or shrinks you could dynamically increase the cell size with a little javascript.
The <colgroup> tag specifies a group of one or more columns in a table for formatting. The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.
you can try do add a colspan="2" to your TD to make it wider.
You have to give specific (non percentage) width to the first column (initial width can be calculated based on initial window size).
E.g.
HTML
<table cellspacing="0" cellpading="0" border="0">
<tr>
<td>Here is column 1</td>
<td>Here is column 2</td>
</tr>
</table>
CSS
table {
font-size:40px
}
tr > td:first-child {
width:280px;
}
DEMO
http://jsfiddle.net/hyrvn/1/
Try resizing bottom-right window to the right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With