CSS:last-of-type不使用多个类

时间:2016-05-20 09:30:41

标签: html css

我有以下带CSS的html。 http://jsfiddle.net/3zcwwjj5/4/

表是动态的,因此列数可能不同。 如何(使用CSS)我可以使用类 comment 选择最后一个表格单元格。 我的CSS无效。

<table>
<tr>
  <td class="comment">1</td>
  <td class="something">2</td>
  <td class="comment">3</td>
  <td class="comment">4</td>
  <td class="something">5</td>
</tr>
<tr>
  <td class="comment">1</td>
  <td class="something">2</td>
  <td class="comment">3</td>
  <td class="comment">4</td>
  <td class="something">5</td>
</tr>
</table>

.comment:first-of-type {
    background: red;
}

.comment:last-of-type {
    background: blue;
}

.something:first-of-type{
    background: yellow;
}

.something:last-of-type{
    background: magenta;
}

0 个答案:

没有答案