在一张桌子上,所有人<th>
都有class
和<td>
没有。
是否可以将这些样式应用<th>
class
到所有相应<td>
的样式中,css
并且不需要任何样式script
?
此外table
是动态的,因此列索引可能会有所不同。所以我不能使用nth-child
,我只能用它来导航它class
。
这是小提琴
跨浏览器有更好的想法吗?
更新:
表可能有n
列数,但不限于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.
尝试这个
<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>