It is done in order of specifity. In this case, ul:last-child is more specific because it has two conditions:
- It has to be a ul
- It has to be the last child
Whereas your second style only has one condition:
- It has to have the class content-message
In order to make the second style as specific as the first you need to add another condition:
ul.content-message {
margin: 20px -1.667em -1.667em -1.667em;
margin-bottom: -1.667em;
}
Because the two rules are equally as specific, the second rule takes precedence because it is written last. Note that this is a simplification of css specificity - the ordering works something like this:
- Inline styles with !important
- Stylesheet styles with !important
- Inline styles without !important
- Selectors containing an id (#myItem)
- Classes, tag names, pseudo classes etc.
Any selector from higher up the list will take precedence, while two selectors from the same level will be determined by how many of that type there are (so two classes are less specific than an id, but as specific as a style and a tag). Two styles will the same weighting will defer to the last defined style.
I may be wrong on all items in point 5 having equal weighting, but for a better understanding check out http://www.adobe.com/devnet/dreamweaver/articles/css_specificity.html or similar articles found on Google.