This is done in order of clarification. In this case, ul: last-child is more specific because it has two conditions:
- It must be ul
- He must be the last child
While your second style has only one condition:
- It must have a class content message.
To make the second style concrete, like the first, you need to add another condition:
ul.content-message { margin: 20px -1.667em -1.667em -1.667em; margin-bottom: -1.667em; }
Since the two rules are equally specific, the second rule takes precedence because it is written last. Note that this is a simplification of css specificity - ordering works something like this:
- Built-in styles with! important
- Styles styles with! important
- Inline styles without importance
- ID Selectors (#myItem)
- Classes, tag names, pseudo-classes, etc.
Any selector from the list above will take precedence, while two selectors from the same level will be determined by how many of them exist (therefore, two classes are less specific than an identifier, but have a special character like style and tag). In two styles, the same weighting will apply to the last defined style.
Perhaps I am mistaken in all points of the fifth paragraph that have the same weighting, but for a better understanding check http://www.adobe.com/devnet/dreamweaver/articles/css_specificity.html or similar articles on Google.
source share