我有一个如下所示的 CSS,用于在将鼠标悬停在表格上时创建特定的背景颜色。
.cb_table-hover tbody tr:hover td ,
.cb_table-hover tbody tr:hover th {
background-color: #cfe2e8;
}
在 <td>
内我有一个 <div>
,我想从这种悬停颜色疯狂中排除。
<td>
<div class="override_td">
{% include '_test_edit.html' %}
</div>
</td>
所以我想出了一个对初始悬停 css 的否定。
.cb_table-hover tbody tr:hover td:not(.override_td) ,
.cb_table-hover tbody tr:hover th:not(.override_td) {
background-color: #cfe2e8;
}
但似乎我已经惨败了,因为我的 Aptana Studio 大声疾呼
The negation pseudo-class,
:not(X)
, is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument. Negations may not be nested;:not(:not(...))
is invalid. Note also that since pseudo-elements are not simple selectors, they are not a valid argument to:not()
.Example The following selector matches all button elements in an HTML document that are not disabled.
button:not([DISABLED])
The following selector represents all but FOO elements.*:not(FOO)
The following group of selectors represents all HTML elements except links.html|*:not(:link):not(:visited)
所以我很困惑为什么它不喜欢我的选择器?
最佳答案
根据 this fiddle,您的选择器看起来格式正确(并遵循 Aptana 警告消息中列出的规则)并且工作正常.您没有提到实际失败(只是 Aptana 的投诉),所以我认为它会正常工作。
Aptana 提示的原因可能是它没有非常仔细地扫描无效的 :not
。有可能仅仅因为您的选择器字符串包含两个 :not
伪类,Aptana 就认为它们是无效的,即使它们被逗号分隔也是如此。
关于css - 从其父项中排除此子项的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13919777/