你的桌子应该有直接的孩子只是tbody和thead元素,行内*。所以,修改HTML是:
| |
table 1 | |
table 1 | |
table 1 |
然后将您的选择器稍微修改为:
#test>tbody>tr:last-child { background:#ff0000; }
…separates two selectors and matches only those elements matched by the second selector that are direct children of elements matched by the first.
因此,您只针对ticon元素的直接子元素,它们本身就是#test表的直接子元素。
替代解决方案
以上是最整洁的解决方案,因为您不需要过度的任何风格。 The alternative将坚持使用您目前的设置,并超越内部桌面的背景风格,如下所示:
#test tr:last-child { background:#ff0000; }
#test table tr:last-child { background:transparent; }
*这不是强制性的,但大多数(所有?)浏览器将添加这些,所以最好让它明确。正如@BoltClock在评论中所说的:
…it’s now set in stone in HTML5, so for a browser to be compliant it basically must behave this way.