我想给一行添加一个CSS类,使第一列为黑色,第二列为红色。 我不想使用colgroup,因为这是针对一行特定的操作,而不是整个表格应该受到影响。
我想给一行添加一个CSS类,使第一列为黑色,第二列为红色。 我不想使用colgroup,因为这是针对一行特定的操作,而不是整个表格应该受到影响。
你可以使用:
td { color: black; }
td:nth-child(2) { color: red; }
tr:nth-child(even) { td:nth-child(2) { color: red; }}
- 3kstc这是可以在不使用CSS3的情况下实现的!
示例
http://jsfiddle.net/Q3yu5/1/
CSS
tr.special_row td {
background-color: #000;
}
tr.special_row td + td {
background-color: #f00;
}
tr.special_row td+td+td {
background-color: #fff;
}
HTML
<table>
<tr class="special_row">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
tr
编辑为更具体的规则。 - Smamatti……这是一种针对特定行的操作,不应影响整个表格。
然后,对给定行的第一列和第二列应用不同的样式可能会很有用:
<style type="text/css">
td.first
{
background-color: black;
color: white;
}
td.second
{
background-color: red;
color: white;
}
</style>
<table>
<tr>
<td class="first">1st row, 1st column</td>
<td class="second">1st row, 2nd column</td>
</tr>
<tr>
<td>2nd row, 1st column</td>
<td>2nd row, 2nd column</td>
</tr>
</table>
不应该影响整个表格
- Smamatti