html-tablenowrap

nowrap on td in table but not if colspan


Is it possible to control nowrap of table cells depending on if the cell (td) has a colspan attribute or not?

Current css

.k2table {table-layout: fixed; width:100%;border-collapse: collapse}
.k2table tr {height:18px} 
.k2table td {text-align: left;padding:1px;white-space: nowrap;} 
.k2table td+td {text-align: right;width:70px;} 
.k2table td+td+td {text-align: right;width:70px;} 

If I have a table such as below I don't want nowrap on the td with colspan.

<table class="k2table">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>

Solution

  • You can do that using an [attr] selector

    .k2table td[colspan] { white-space: normal }
    

    If you need to be more specific you can apply your style just to the cell with THAT colspan

    .k2table td[colspan="3"] { white-space: normal }