After our team launched the new College of Education site, I discovered that IE8’s handy “Browser Mode: IE7” mode of IE8 is useless for real IE7 testing (but IETester actually works!). Undoubtedly this “IE7 mode” has many quirks in its emulation we’ll never know about, but after a few hours of hair-pulling I finally pinned down a real IE6/7 bug that the emulator doesn’t have.
IE versions before 8 apparently vary in their calculation of CSS specificity depending on the order of elements in the selectors. What this means for poor suckers who worry about IE6/7 is that rules that appear later and (should) match specificity won’t always override values. E.g.
<div id="foo"><div id="bar">I should be green.</div></div>
/* both rules have the same specificity */
#foo div { background:red /* IE6/7 apply this value */ }
div #bar { background:green /* correct value to apply */ }
This bug will hit you when you’re pursuing a good goal: trying to keep selectors short. So in these situations make sure to test in IETester at the very least and leave a comment to let future CSS editors know why a selector is longer than needs to be.
Looks like this bug was already documented in Gérard Talbot’s HUGE IE7 bug list.
Thanks for pointing this out Steve.
I agree. I mentioned this particular issue in IE blog in 2008 (so far, I have not found exactly where but am still searching and am 100% convinced I have reported this issue): the last (in order of appareance) rule with same media, same importance, same origin, same specificity bug in IE7 was not reproducible with IE8 in IE7 mode but only with the real IE7.
I also examined the testcases in latest RC6 of CSS 2.1 test suite, section 6.4.1 and there is no testcase testing the “sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins” code situation. So, this testcase should be submitted.
When I created my IE7 bugs collection, I remember that Tino Zijdel was the first to mention this bug:
IE specificity bug v1 and IE specificity bug v2 (his tests trigger backward-compatible “quirks” rendering mode though).
I can submit a testcase and add your name and Tino Zijdel (will try to reach him) in the credits list. You may want to read:
Web authors’ contributions to CSS 2.1 test suite
and then view
Contributions to the CSS 2.1 test suite
regards, Gérard Talbot
Steve Clay,
I have created
CSS Test: Casdading order – sort by order specified
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/sort-by-order-001.html
It is listed here:
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/#incoming
If you want your name added in the credits link, then please read the 2 pages mentioned in my previous post.
Because of the compatibility-view bug for such testcase (but also another, which I reported also before: try #bug117:
http://www.gtalbot.org/BrowserBugsSection/MSIE7Bugs/AdjacentSiblingSelectorBug.html : the IE7 compat-emulator view has a bug for such page), the testcase should be included in the CSS 2.1 test suite.
One other important question is if IE9 (when triggering IE7 standards mode) still has such bug.
regards, Gérard
A testcase has been submitted to the CSS 2.1 test suite and has been approved:
CSS 2.1 test suite, nightly snapshot, section 6.4.1 has this testcase :
CSS Test: Casdading order – sort by order specified
regards, Gérard Talbot