TL answer DR
The first rule is more specific than the second, because it has both a type and an attribute for the selector and, therefore, takes precedence:
input[type="text"] { } .top_bar_login_form_input { }
Longer answer
You think that the type="text" bit, which is an attribute selector, is more specific than a class selector, according to the specific MDN page :
The following list of selectors is an increase in specificity:
- Universal Selector Functions
- Type selector
- Class selector
- Attribute selectors
- Pseudo-classes
- ID selectors
- Inline style
The above quote was in an MDN article at the time of writing this answer.
Why is this misleading:
(Tanks to @BoltClock hints .)
The above only seems to be correct, but that is because you usually include an element in a selector (for example, input[type="text"] ) when executing an attribute selector. However, that is sneaky: the input bit matters.
Suppose we have the following markup:
<input class="my-class" type="text" value="some value" />
In the following scenario, the input displays red :
[type="text"] { color: green; } .my-class { color: red; }
If we change the rules in the script , the tab will display green :
.my-class { color: red; } [type="text"] { color: green; }
This is due to the fact that both selectors have the same specificity. Now, introducing the input selector into the attribute rule will make one of them more specific, which can be seen in this scenario :
input[type="text"] { color: green; } .my-class { color: red; }
the W3 spec makes my head hurt, but it has information on why this works. See Also @BoltClock answer and comments in these code examples for information on how specifics are calculated.