负CSS选择器 [英] Negative CSS selectors

查看:162
本文介绍了负CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有某种负CSS选择器?



例如,当我在CSS中写下面这行时, em> classname 将具有红色背景。

  .classname input {background:red;} 

如何选择属于 classname 类别的标签外部的所有输入字段?

解决方案



使用目前的浏览器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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆