让我们得到开门见山,我创造了这个例子跨越,以更好地让我的观点:影响父只
HTML: 表1
<table class="testClass">
<tr>
<td>Inner table
<table>
<tr>
<td>Hello</td>
<td>Testing testing</td>
<td>Bye</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<br />
<br />Table 2
<table class="testClass">
<tr>
<td colspan="3">stuff</td>
</tr>
<tr>
<td>Left</td>
<td>Middle</td>
<td>Right</td>
</tr>
</table>
CSS:
table {
border: 2px solid red;
width: 100%;
}
td {
border: 2px solid blue;
}
/* Relative CSS */
.testClass tr:last-child td:nth-child(1) {
width: 15px;
}
.testClass tr:last-child td:nth-child(2) {
width: auto;
}
.testClass tr:last-child td:nth-child(3) {
width: 15px;
}
所以我们有2个表,两个表都是相同的类。 Table 1
有一个表格,其中Table 2
没有。
我发现这个问题是使用我创建的CSS,我无法停止受影响的子表(内表).testClass
的样式。我认为:not()
可以使用,但我无法找到解决方案,我觉得这应该不是那么难。
是否有可能只影响从父进入子表的样式中的父亲?
注意:只能更改CSS而不是HTML。 CSS3可以使用!
我希望这是有道理的,如果我需要使它更清晰,请发表评论。
为什么不使用类似'.testClass> tr ...'的东西来设计只有可怕ct孩子?像[this](http://jsfiddle.net/urryfof5/2/)。 – Harry 2014-08-29 09:51:00
@Harry这应该是'.testClass> tr,。testClass> tbody> tr',因为大多数现代浏览器都会自动插入表格主体。 – feeela 2014-08-29 09:53:17
@feeela:是的,好点。 – Harry 2014-08-29 09:55:50