Yes, the second selector has higher specificity.
#someId
is just a single ID and will select any element with that ID regardless of what element it is. a#someId
is both an element and an ID, making it more specific as it will only select anchor a
elements with that ID.
There is a common trick to calculating specificity and comparing the specificity of different selectors, which is to count the IDs, classes, and elements like X,X,X. The most specific selector is the one with the highest leftmost number (if that is a tie, move to the next number).
#someId
is just an ID, so it's 1,0,0.
a#someId
is an ID and an element, so it's 1,0,1 and therefore more specific.
IDs are always more specific than classes and classes are always more specific than elements. Psuedo-elements count as elements and psuedo-classes count as classes for the purposes of calculating specificity. Technically 256 elements = 1 class and 256 classes = 1 ID, but if you ever have that much going on in a selector string you have way bigger problems to worry about.
The only thing more specific than an ID (besides a selector string containing several IDs) is a style with !important
or an inline style declared via the style
attribute on the element.
More about CSS Specificity: