3

在一张桌子上,所有人<th>都有class<td>没有。

是否可以将这些样式应用<th> class到所有相应<td>的样式中,css并且不需要任何样式script

此外table是动态的,因此列索引可能会有所不同。所以我不能使用nth-child,我只能用它来导航它class

这是小提琴

跨浏览器有更好的想法吗?

更新:

表可能有n列数,但不限于2

4

2 回答 2

2

You could handle this using <col>, http://www.quirksmode.org/css/columns.html#background, only other way I see would need to add the classes everywhere or to use JS.

于 2013-01-29T13:32:01.380 回答
-1

尝试这个

<table>
<tr>
    <th class="a">`Column A`</th>
    `<th class="b">`Column B`</th>
</tr>
<tr>
    <td class="a">`aaa`</td>
    <td class="b">`bbb`</td>
</tr>
<tr>
    <td class="a">`ccc`</td>
    <td class="b">`ddd`</td>
</tr>
</table>
于 2013-01-29T13:23:16.330 回答