12

I have CSS rules for input as

input {
background:#FFFFFF
}
input:hover {
background:#BBBBBB
}

I want to apply this style to all input elements, except one (e.g., type="submit").

How can I exclude one input type from a CSS style?

3 Answers 3

34

You can use the :not() pseudo-class and an attribute selector, e.g.

input:not([type=submit]) {
    background: slategray;
}

Keep in mind there is no support for IE 8 and below.

http://jsfiddle.net/qpxYb/1/

Sign up to request clarification or add additional context in comments.

3 Comments

I knew about not, but how can I use it with :hover?
Just attach it at the end, e.g. input:not([type=submit]):hover {}
add :hover behind the selector
5

You may use the :not() selector.

input:not([type='submit']):hover {
/* rules here */
}

http://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:not

Comments

2

You can just overwrite the general input field style with a new style for submit input fields. Check it out: http://jsfiddle.net/dpYRX/2/

input {
background:#FFFFFF
}
input:hover {
background:#BBBBBB
}

input[type="submit"] {
    background: #ff0000;
}

input[type="submit"]:hover {
    background: #cdcdcd;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.