As David Dorward said, there is no way to do exactly what you want with CSS, but I can come up with a few workarounds ...
Assuming your html is something like this (i.e. the thing with the background color is the only thing in the table cell):
<table> <tr> <td>test with longish string<br/> over two lines<td> <td><span class="bg" >test</span></td> </tr> <tr> <td>test with longish string<br/> over two lines<td> <td>test with longish string<br/> over two lines<td> </tr> </table>
You can do this for your CSS:
td { height: 100%;} .bg { background-color: #f00; width: 100%; height: 100%; display: block; }
It works in this simple example (at least in firefox 3.5), but may have other side effects depending on how your html content looks.
Change Another option, if you're fine with hacking it through javascript, is to use jQuery as follows:
$(function() { $("td:has(span.bg)").addClass("bg"); });
This works on the above html / css example, but obviously, it will need to be modified according to your css classes, etc.
Alconja
source share