1

I want to style ALL inputs except for specific types.

For example:

input,
input:not(type='email') {
    background: red;
}

The above doesn't work

So I want all inputs to have a background of red (obviously I don't this is just an example), except for input elements of type email. The type I am trying to target with the :not selector could be different.

Can this be acheived? If not, what is the best solution?

If you're curious I am trying to avoid specifying all types of input that I want to target just so the types I don't want targeting don't get that style.

2 Answers 2

5

You have to do it like this: fiddle

input:not([type='email']) {
    background: red;
}

Because if you dont use the [] your not making a selector. Also this does not support all older browsers

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

1 Comment

can multiple types be targetted? e.g. I want all inputs to be red except types email AND number. After some experimenting I discovered it can be done with input:not([type="email"]):not([type="number"]),
3

Try:

input:not([type='email'])

Keep in mind though, that by using input, input:not([type='email']) you're actually rendering the condition useless since you're specifying a bare input as well.

1 Comment

can multiple types be targetted? e.g. I want all inputs to be red except types email AND number. After some experimenting I discovered it can be done with input:not([type="email"]):not([type="number"]),

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.