GuyB7 GuyB7 - 1 month ago 7
CSS Question

TD width - the minimum needed using CSS

Consider this table:



<table style="width: 100%">
<tr>
<td>Static length</td>
<td>Static length</td>
<td><div>Length varies</div></td>
<td>Space filler</td>
</tr>
<tr>
...
</tr>
</table>


How can I make the 3rd column to take the minimum width (depending on its content) and the 4th column to take the rest?

Answer

Use this

td:nth-child(3){
    background:red;
    width: 1px;
    white-space: nowrap;
}

DEMO