tags:

views:

108

answers:

5

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

input {
 ... 
 ...
}

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

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

which simple skip this tag from CSS...

How I can do that? Only one way I can see, it's to add some class to input tag, and rewrite as the following:

input.mod {
 ...
 ...
}
+1  A: 

You can also do that by 'reverting' the changes on the reset class only in CSS.

INPUT { 
    padding: 0px;
}
INPUT.reset {
    padding: 4px;
}
AvatarKava
+3  A: 

CSS3 has :not(), but it's not implemented in all browsers yet. It is implemented in the IE9 Platform Preview, however.

input:not(.reset) { }

http://www.w3.org/TR/css3-selectors/#negation

In the meantime, you'll have to stick to the old-fashioned methods.

Andy E
+5  A: 

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; }
Tomas Lycken
OMG... I knew that it's exist :)Yeah, it is! Thanks.
Alex Ivasyuv
A: 

I think you can't with plain css, you will need something like Jquery or Mootools, or a custom library for that.

jahmax
A: 

instead of class="reset" you could reverse the logic by having class="valid" You can add this by default and remove the class to reset the style.

So from your example and Tomas'

input.valid {
 ... 
 ...
}

and

<input type="text" value="will be matched" class="valid"/>
<input type="text" value="will not be matched" />
<input type="text" value="will be matched" class="valid"/>
Qazzian
I think the whole idea of being able to "reset" by applying to a class was that the number of elements that shouldn't have the default style greatly exceeded the ones that should, so the OP didn't want to apply *any* class to the majority of the elements.
Tomas Lycken