Check out the response provided by @Jukka as it appears that the original poster has altered the question slightly through edits. However, if you're interested in the specifics of the initial question before the edit, keep reading.
Neither of the selectors used seem to be logical and are actually considered too specific. Your selector already includes an id
, making the addition of a class
or attr=val
unnecessary unless this same id
is being used for another element in a different document.
If there arises a need to use additional specificity to override properties, then the following can be done:
input#foo.bar[name=baz] {
/* More specificity overrides the selector below */
}
input[name=baz] {
/* Styles here */
}
The question of whether the selectors mentioned above are equal - the answer is YES, they possess the same level of specificity which amounts to a score of 121.
Credits
Regarding their validity - they are deemed Completely Valid.
Does the order of tags, id
, or class
matter? - The answer is NO, the order of attributes does not affect the outcome.
However,
The order of your CSS declaration block within the stylesheet does make a difference; the last selector will take precedence over common properties since all three selectors have equal specificity.
Demo (All three will render green text, regardless of the order of their attributes. If you rearrange the CSS selectors block, the last one will override the shared properties of the prior two selectors - unless you include !important
in one of the selector properties)
Is it possible to reposition the name
attribute value to the end? - Absolutely, YES
Pros & Cons —
- All the selectors are excessively specific
- Impacts performance negatively
- By using an
attr=val
selector, you are assuming that the value of the name
attribute remains static. Any changes in these values would necessitate updating your selectors accordingly.
P.S : Make it a practice to quote attribute values.