Your question is answered by the CSS3 selectors, W3C Recommendation:
9. Calculating a selector's specificity
A selector's specificity is calculated as follows:
- count the number of ID selectors in the selector (= a)
- count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
- count the number of type selectors and pseudo-elements in the selector (= c)
- ignore the universal selector
Selectors inside the negation pseudo-class are counted like any other,
but the negation itself does not count as a pseudo-class.
Concatenating the three numbers a-b-c (in a number system with a large
base) gives the specificity.
With your examples we have:
1) p#largetext
has a specificity of 1,0,1 (1 id, 1 type)
body p#largetex
has a specificity of 1,0,2 (1 id, 2 types)
2) p.largetext ul li
has a specificity of 0,1,3 (1 class, 3 types)
p ul li a
has a specificity of 0,0,4 (4 types)
To obtain the value of the specificity you have to concatenate the 3 numbers. So for example 1, the second selector is more specific 102>101 and for example 2, the first selector is more specific 13>4.