Test 1: This background should be green
Test 2: This background should be green
Test 3: This background should be green
Test 4: This background should be green

IE6/7 CSS Specificity Miscalculation

In each set of rules below, both rules apply to the same element and have selectors with identical specificity. IE before version 8 fails to apply the latter background value.

/* Tests 1 and 2: specificity (1,0,1) */
#foo div  { background:red   }
div  #bar { background:green }

div   #bar2 { background:red   }
#foo2 div   { background:green }

/* Tests 3 and 4: specificity (0,1,1) */
.foo div  { background:red   }
div  .bar { background:green }

div   .bar2 { background:red   }
.foo2 div   { background:green }

Particularly, the affected browsers seem to apply greater specificity when the id/class part of the selector comes before the element name.

Note: The "Browser Mode: IE7" emulation in IE8 does not display this bug, which severely reduces the value of this tool for testing IE7 rendering.