有没有CSS不等于选择器? [英] Is there a CSS not equals selector?

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

问题描述

在CSS中有类似!=(不等于)的东西吗?
例如,我有以下代码:

 输入{
...
。 ..
}

但是对于一些输入,我想通过添加类reset到输入标签,例如

 < input class =复位... /> 

,然后从CSS中跳过此标记。



我可以看到的唯一方法是将一些类添加到输入标签,并重写CSS如下:

  input.mod {
...
...
}


解决方案

在CSS3中,可以使用:not )过滤器,但并非所有浏览器都完全支持CSS3,因此请确保您知道自己在做什么。



示例:

 < input type =textvalue =will match/> 
< input type =textvalue =will not be matchedclass =avoidme/>
< input type =textvalue =will be matched/>

和CSS

 输入:not(.avoidme){background-color:green; } 

如果不想使用CSS3,可以设置所有元素的样式,然后用类重置它。

  input {background-color:greeen; } 
input.avoidme {background-color:white; }


Is there something like != (not equal) in CSS? e.g, I have the following code:

input {
 ... 
 ...
}

but for some inputs I need to void this. I'd like to do that by adding the class "reset" to the input tag, e.g.

<input class="reset" ... />

and then simply skip this tag from CSS.

How I can do that?

The only way I can see would be to add some class to the input tag, and rewrite the CSS as follows:

input.mod {
 ...
 ...
}

解决方案

In CSS3, you can use the :not() filter, but not all browsers fully support CSS3 yet, so be sure you know what you're doing.

Example:

<input type="text" value="will be matched" />
<input type="text" value="will not be matched" class="avoidme" />
<input type="text" value="will be matched" />

and the CSS

input:not(.avoidme) { background-color: green; }

If you don't want to use CSS3, you can set the style on all elements, and then reset it with a class.

input { background-color: greeen; }
input.avoidme { background-color: white; }

这篇关于有没有CSS不等于选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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