负CSS选择器 [英] Negative CSS selectors
问题描述
是否有某种负CSS选择器?
例如,当我在CSS中写下面这行时, em> classname 将具有红色背景。
.classname input {background:red;}
如何选择属于 classname 类别的标签外部的所有输入字段?/ p>
使用目前的浏览器CSS支援, / strong>
较新的浏览器现在支持它 - 请参阅 Sam的回答以获取更多信息。
p>
如果在JavaScript / jQuery中执行此操作,您可以执行:
$ j(':not(.classname)> input')。css({background:'red'});
Is there some kind of "negative" CSS selector?
For example when I write the following line in my CSS, all input fields inside an tag with class classname will have a red background.
.classname input {background: red;}
How do I select all input fields that are OUTSIDE of a tag with class classname?
With current browser CSS support, you can't.
Newer browsers now support it- see Sam's answer for more info.
(See other answers for the alternatives in CSS.)
If doing it in JavaScript/jQuery is acceptable, you can do:
$j(':not(.classname)>input').css({background:'red'});
这篇关于负CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!