1

How can I override the CSS on the input[type=text] selector without using !important?

input[type=text]{
    background-color: rgb(255, 255, 255);
}

/*This doesn't work */
.bb-input{
    background-color: yellow;
}
0

3 Answers 3

3

input.bb-input would do. The attribute selector and class selector have the same specifity. The type selector is adding additional specificity to the first selector.

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

1 Comment

Perfect! just what i was looking for :)
2

The first selector is more specific then the second:

CSS Specifity Disclaimer: This is my blog

the class and the attribute have the same weight. The problem is that the first selector input[type="text"] also has the input element, which makes it more specific.

one way you can solve it is by renaming your second selector to

input.bb-input {
   ...
} 

Comments

0

inline styling has highest priority so use inline styling

<input type="text" style="background-color: yellow;">

it will override external if no !important is used

2 Comments

Not a great solution if the code contains 20 input tags.
ya generally when 20 inputs are used. we use server side scripting to generate inputs then we can apply inline styling because we only have to write once in script @mbnyc

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.